标签 php 下的文章

phpsession失效

一个基于thinkphp的项目,session设置无效
在a.php页面设置完session之后,可以打印出session的值,但是刷新之后就又没了
在服务器新建一个可以访问的php文件

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
session_register('A');
$_SESSION['A'] = 10;
echo $_SESSION['A'];
?>

访问,报如下错误,

Warning: session_start(): open(/var/lib/php/session/sess_veiso2o3bco5do2mlkvhi18jq5, O_RDWR) failed: Permission denied (13) in /home/xxx.com/public_html/test1.php on line 4 Deprecated: Function session_register() is deprecated in /home/xxx.com/public_html/test1.php on line 5 10 Warning: Unknown: open(/var/lib/php/session/sess_veiso2o3bco5do2mlkvhi18jq5, O_RDWR) failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

修改session的目录为程序有权限操作的目录即可
修改thinkphp入口文件,在定义 APP_PATH 的代码下加上

session_save_path(APP_PATH . 'Runtime/session/');

nginx报502

nginx经常报这样的错误

2016/10/28 16:46:44 [error] 1919#0: *4340 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: www.xxxxx.com, request: "GET /test1.php HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000", host: "www.xxxxx.com"

与此同时,php-fpm 也会报这样的错

Oct 28 16:46:44.654727 [WARNING] [pool www] child 2175 exited on signal 7 SIGBUS after 0.025646 seconds from start
Oct 28 16:46:44.655233 [NOTICE] [pool www] child 2178 started

百度之后,看到一边文章

原因是在php包含了一个文件之后,这个文件又发生了修改,于是发生了错误
重现错误可以使用如下代码,使用ab测试,就会报这样的错误

<?php

file_put_contents(__DIR__ . '/test.tpl', 'AAA<?php $string = "'. str_repeat('A', mt_rand(1, 256 * 1024)) .'"; ?>BBB' . "\r\n", LOCK_EX);

require_once __DIR__ . '/test.tpl';

echo "111";

?>

处理方法:
1、减少修改被包含的文件,模版解析之后的模版缓存文件

configure: error: libevent >= 1.4.11 could not be found

编译php5.3.3的时候报错
编译选项

./configure --prefix=/usr/local/php-5.3.3 \
--with-config-file-path=/usr/local/php-5.3.3/etc \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--with-iconv-dir=/usr/local \
--enable-mbstring \
--enable-calendar \
--with-gettext \
--with-libxml-dir=/usr/local \
--with-zlib \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-mysql=mysqlnd \
--enable-dom \
--enable-xml \
--enable-fpm \
--enable-debug \
--with-libdir=lib64

错误信息

configure: error: libevent >= 1.4.11 could not be found

安装相关的包

yum -y install libevent

依然报错
还是失败了,继续google,发现有人在ubuntu里面也遇到这个问题,再安装libevent-dev这个包之后解决问题了,于是我依样画葫芦:

yum -y install libevent-dev

安装完成

php-fpm开启core dump

转载自:https://kn007.net/topics/php-fpm-how-to-core-dump/
首先一点,需要打开debug参数,如果编译的时候没有打开,需要重新编译,编译时添加参数:

--enable-debug

设置内核core dump出来的存放路径(注意目录要有权限给php写):

echo "/tmp/core.%e.%p.%t" > /proc/sys/kernel/core_pattern

设置core dump出来的文件大小不做限制:

ulimit -c unlimited

关闭core dump只需要将大小限制为0就不会输出了(获得调试信息后设置这个就关闭core dump了)

ulimit -c 0

测试core dump是否开启成功
创建c程序文件

vim a.c
#include <stdio.h>;
int func(int *p)
{
        *p = 0;
}
int main()
{
        func(NULL);
        return 0;
}
gcc -o main a.c#编译
./main#执行,然后就会出现这个文件了

获得core dump文件,用gdb进行调试,比如:

gdb ~/main core.main.5021.iZ23sw4oxfvZ.1477623334

打开php-fpm的slowlog

  1. 编辑 php-fpm 配置文件
    最近在在转移一个discuz站点的时候,打开网站一直处在请求状态,服务器不返回任何东西,也不结束连接,因为是测试服务器,机器的负载也非常低,cpu内存什么的基本上没使用,打开一个只有一句phpinfo函数的页面又是正常的,问题也不知道如何排除,然后打开php-fpm的slowlog来追踪是哪里代码出的问题


修改request_slowlog_timeout,例如:

;10代表达到或者超过10秒的脚本
request_slowlog_timeout=10
;日志路径
slowlog = /tmp/slow.log
  1. 重启 php-fpm 即可