PHP7 學習筆記(二)PHP5.9 升級到PHP7 遇到的一些坑的記錄(php-fpm 圖解)


apache_event_php-fpm 示意圖:


 

nginx-php-fpm示意圖:


 

 

 

Worker-Master-Server


 TCP-Nginx_PHP


Nginx-FastCGI


 

 

1、使用$_GET 獲取所有參數,php7 會多出一個參數:_url ,例如訪問的地址

http://127.0.0.1/Home/String/index2?a=12&b=19

 此時的的參數_url = "Home/String/index2"

2、在PHP7 中為一個Error:PHP Notice: Undefined index: HTTP_USER_AGENT in line 2 

  php5.9則為一個notice 

2017/03/27 10:58:09 [error] 5286#0: *851 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined index: HTTP_USER_AGENT in /home/UserAgent.php on line 9" while reading response header from upstream

解決:http://stackoverflow.com/questions/16330496/php-notice-undefined-index-http-user-agent-in-line-2

if(!empty($_SERVER['HTTP_USER_AGENT'])){
  $user_agent = $_SERVER['HTTP_USER_AGENT'];    
} else {
  $user_agent = ''; 
}

3、NULL 合並運算符 ,PHP7才正式加入了??這個運算符:

// 獲取user參數的值(如果為空,則用'nobody')
$username = $_GET['user'] ?? 'nobody';
// 等價於:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';

 4、php-fpm 沒有啟動的后果

2017/03/31 20:56:19 [crit] 19288#0: *1 connect() to unix:/var/run/php7.0.9-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, 
server: www.phalcon3.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php7.0.9-fpm.sock:", host: "127.0.0.1"
tinywan@tinywan:/usr/local/nginx/logs$ ll /var/run/php7.0.9-fpm.sock
ls: 無法訪問'/var/run/php7.0.9-fpm.sock': 沒有那個文件或目錄

搞了半天,原來php-fmp 沒有啟動,


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM