1. ホーム
  2. Qt

LNMP nginx1.4.6+php5.5.11+mysql5.6.17+mecache+opcache コンパイルとインストール+opcacheパラメータ詳細+opcacheビジュアルPHPページコード

2022-02-09 17:36:59

<スパン が必要な場合があります。 使用するソフトウェア

libiconv-1.13.tar.gz 
libmcrypt-2.5.8.tar.gz 
mcrypt-2.6.8.tar.gz 
mhash-0.9.9.tar.gz 
memcache-2.2.5.tgz 
PDO_MYSQL-1.0.2.tgz 
imagick-3.1.2.tgz 
pcre-8.21.tar.gz 
mysql-5.6.17.tar.gz 
ImageMagick.tar.gz 
php-5.4.21.tar.gz 
nginx-1.4.6.tar.gz 

<スパン システムのインストール要件。
centos 6.4 *86_64 ミニインストール

<スパン 1 Resolving Dependencies(空の星を選ぶ奉納品)をインストールする。
yum install -y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-CPAN libpng libpng-devel freetype freetype-devel libxml2 libxml2- devel zlib zlib-devel glibc glibc- glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-... devel nss_ldap openldap-clients openldap-servers png jpeg autoconf gcc cmake make gcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre- static openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2 ImageMagick-devel jpeg jpeg* pcre-dev* fontconfig libpng libxml2 zip unzip gzip
でコンパイルした場合 のようなエラーが発生した場合 次のように perl-xxx エラー
Error: perl-JSON-PP conflicts with perl-JSON-2.15-5.el6.noarch Error: Perl-JSON-PP conflicts with perl-JSON-2.15-5.el6.noarch Error: パッケージ: perl-Image-SubImageFind-0.03-1.el6.x86_64 (epel) Requires: libMagick++.so.2()(64bit) Error: Error: パッケージ: perl-Image-SubImageFind-0.03-1.el6.x86_64 (epel)
この問題を回避するために、-skip-brokenを使用してみてください。
yum installのインストールからperl*を削除する <スパン yumをインストールし直すだけ

<スパン <スパン 2 使用するソフトをすべてダウンロードする。

<スパン wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz
wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://vps.googlecode.com/files/PDO_MYSQL-1.0.2.tgz
wget http://pecl.php.net/get/imagick-3.1.2.tgz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
wget http://mynginx.googlecode.com/files/ImageMagick.tar.gz
wget https://lnamp-web-server.googlecode.com/files/eaccelerator-eaccelerator-42067ac.tar.gz

NGINX1.4.6: http://nginx.org/download/nginx-1.4.6.tar.gz

MYSQL 5.6.17 http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz

PHP5.5.11 http://us1.php.net/get/php-5.5.11.tar.gz/from/this/mirror

以前は、異なる MYSQL バージョンを持つ 2 つの別々のマシンで 2 回コンパイルしていました。 MYSQL5.6.12とMYSQL5.6.17のコンパイルコマンドです。 どちらも以下の通りです。
cmake ୧⃛(๑⃙⃘◡̈๑⃙⃘)
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql ⇦。
-DMYSQL_DATADIR=/usr/local/mysql/data ┣┣┣┣。
-DSYSCONFDIR=/etc "です。
-dwith_myisam_storage_engine=1 \!
-୧⃛(๑⃙⃘◡̈๑⃙⃘)
-⑭メモリ記憶装置付き
-୧⃛(๑⃙⃘◡̈๑⃙⃘)
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock ↘↘↘。
-dmysql_tcp_port=3306 ┣┣。
-denabled_local_infile=1 \ \?
-dwith_partition_storage_engine=1 \...
-DEXTRA_CHARSETS=all \?
-DDEFAULT_CHARSET=utf8 \ \?
-DDEFAULT_COLLATION=utf8_general_ci

<スパン 終了したら、以下を続けてください。

  1. cd /usr/local/mysql 
  2. chown -R mysql:mysql . (セキュリティのため、インストール完了後、rootユーザーに権限を変更してください)
  3. scripts/mysql_install_db --user=mysql (このステップを最初に行い、次のパーミッション変更を行ってください)
  4. chown -R root:mysql . (ルートユーザーと mysql グループに権限を設定し、他のユーザーから読み取りと書き込み権限を削除し、mysql "rx" 読み取り権限だけを残し、他のユーザーは何も権限を持っていません)
  5. chown -R mysql:mysql . /data (データベース格納ディレクトリをmysqlユーザーmysqlグループに設定し、chmod -R ug+rwxの読み取り/書き込み実行権限を与え、他のすべてのユーザー権限はmysqlユーザー権限のためにのみ削除されます)

次のコマンドはオプションで、mysqlの設定ファイルを/etcにコピーします。

  1. cp support-files/my-medium.cnf /etc/my.cnf (オリジナルの古いバージョンではこうなっていました。5.6.12バージョンでは以下のファイルアドレスになっています。)
  2. cp support-files/my-default.cnf /etc/my.cnf (そして /etc/my.cnf に +x パーミッションを与え、他のユーザーの書き込みパーミッションを削除し、ルートとワークグループの rx パーミッションのみを残し、他のすべてを rx パーミッションも含めて削除してください)
#my.cnfの設定を変更する
    vim /etc/my.cnf
    #[mysqld] 追加。
    datadir=/data/mysql
    default-storage-engine=MyISAM

mysqlを起動します。

[c-sharp】(シーシャープ] 表示プレーン <スパン コピー
  1. bin/mysqld_safe --user=mysql &  
  2. #mysqlを起動して成功するか確認する
  3. netstat -tnl|grep 3306  
[c-sharp】(シーシャープ] 表示プレーン <スパン コピー
  1. bin/mysqld_safe --user=mysql &  
  2. #mysqlを起動して成功するか確認する
  3. netstat -tnl|grep 3306  

上記はmysqlを起動する方法の一つですが、以下のような簡単な便利な方法があります。

[c-sharp】(シーシャープ] 表示プレーン <スパン コピー
  1. #システムサービスにmysqlのスタートアップサービスを追加する
  2. cp support-files/mysql.server /etc/init.d/mysql 
  3. # これで、以下のコマンドでmysqlを起動することができます。
  4. サービスmysqlスタート  
  5. #stop mysql サービス
  6. サービスmysql停止  
  7. # mysql サービスを再起動する
  8. service mysql restart  

ブート時にmysqlサービスを起動させるために、ブート起動項目にmysqlサービスを追加します。

[c-sharp】(シーシャープ] 表示プレーン <スパン コピー
  1. chkconfig --add mysql

    デフォルトのルートアカウントのパスワードを変更します。デフォルトのパスワードは空です。

    パスワードの変更 cdはmysqlディレクトリに切り替えます。

    cd /usr/local/mysql

    # . /bin/mysqladmin -u root パスワード

    次のプロンプトで新しいパスワードを設定するには、Enterキーを押します。

    # MySQLを起動する
        /usr/local/mysql/bin/mysqld_safe -defaults-file=/etc/my.cnf &
        #または
        /etc/init.d/mysql start (サービス mysql スタート)
        #MySQLが起動したかどうかテストする
        # 1) プロセスmysqlが利用可能かどうかを確認する
        ps -ef | grep mysql
        # 2) ポートが動作しているかどうか確認する
        netstat -tnl | grep 3306
        # 3) mysqlのバージョン情報を読み込む
        mysqladmin バージョン


PHP5.4.8 共通コンパイルコマンド
. /configure --prefix=/usr/local/php \?
--with-apxs2=/usr/local/apache2/bin/apxs \ #この行はapache+phpでのみ使用されます、nginx+phpでは削除してください
--with-config-file-path=/usr/local/php/etcを指定します。
--with-mysql=/usr/local/mysql \?
--with-mysqli=/usr/local/mysql/bin/mysql_config \ \?
--with-iconv-dir
--with-jpeg-dir
--with-png-dir
--with-zlib
--with-libxml-dir \?
--enable-xml
-disable-rpath(パス)
--enable-bcmath \?
--enable-shmop \ \
--enable-sysvsem
--enable-inline-optimization \ \?
--with-curl
--♪♪~
--enable-mbregex \ \?
--enable-fpm
--enable-mbstring
--with-mcrypt
--with-gd
--with-freetype-dir \?
--enable-gd-native-ttf
--with-openssl
--with-mhash
--enable-pcntl
--enable-sockets
--with-ldap
--with-ldap-sasl
--with-xmlrpc
--enable-zip
--♪♪~
--enable-session \?
--with-gettext ୧⃛(๑⃙⃘◡̈๑⃙⃘)
--enable-pdo
--with-pdo-mysql
--enable-shared
--enable-ftp
--enable-exif
--槍付き
php5.5から以下のオプションコマンドが追加されました。
--enable-opcache
オンラインサーバー デバッグモードは、以下のコマンドを追加することでオフにすることができます。
-disable-debug(ディスエイブルデバッグ)
php5.5.11以降では認識されない非推奨のビルドオプション(WRING警告が認識されない場合は無視してください --with-curlwrappers)。
--with-curlwrappers
NGINXの処理を使用するには、APACHEの下でのみ使用される以下の行を削除してください。
--with-apxs2=/usr/local/apache2/bin/apxs \ \?
NGINXの場合、以下の2行を追加してFPMの実行アカウント権限を指定します。
--with-fpm-user=www \?
--with-fpm-group=www ୧⃛(๑⃙⃘◡̈๑⃙⃘)

PHPコンパイルオプションの説明 :
""" インストールパス """
--prefix=/usr/local/php \?
php.iniの設定ファイルのパス """"
--with-config-file-path=/etc \?
最適化オプション """"。
--enable-inline-optimization \?
-disable-debug(デバッグ不可)
-disable-rpath(ディセーブル・パス)
--enable-shared \?
opcache を有効にします。デフォルトは ZendOptimizer+(ZendOpcache) """" です。
--enable-opcache
""" FPM """
--enable-fpm
--with-fpm-user=www \?
--with-fpm-group=www ୧⃛(๑⃙⃘◡̈๑⃙⃘)
MySQL """" MySQL """"
--with-mysql=mysqlnd \?
--with-mysqli=mysqlnd \...
--with-pdo-mysql=mysqlnd \!
国際化と文字エンコーディングのサポート """。
--with-gettext
--enable-mbstring \?
--with-iconv
暗号化拡張機能 """"
--with-mcrypt
--ウィズ・マハッシュ
--with-openssl
数学的拡張機能 """"
--enable-bcmath
libxml に依存する Web サービス """"。
--enable-soap
--with-libxml-dir
プロセス制御 """""。
--enable-pcntl
--enable-shmop
--enable-sysvsem
ソケット & キュール " """"
--enable-sockets
--with-curl
"""を圧縮してアーカイブします。
--with-zlib
--enable-zip
--with-bz2
GNU Readline コマンドラインショートカットバインディング """"。
--with-readline
SQLite サポート拡張機能 """ を無効にします。
--without-sqlite3 \ \?
--without-pdo-sqlite \ \?
その他の PHP 拡張機能およびアプリケーション ライブラリ """"
--with-pear

LinuxでのPHPのインストール、ソース方式 LinuxでPHPをインストールする場合、ソース方式では常に多くのパラメータを設定する必要があります。ここでは、一般的な設定パラメータをリストアップし、中国語で詳細な解説を行います。ご参考までに

PHPをコンパイルする際には、-with-curlwrappersパラメータを注意して使用してください。

. /configure

-prefix=/usr/local/PHPのPHPインストールディレクトリ 
--with-apxs2=/usr/local/apache/bin/apxs は apache 2.0 以降、apxs は apache 1.0 を使用することを意味します。
--with-config-file-path=/usr/local/PHP/etc php.iniの場所を指定します。
--with-MySQL=/usr/local/mysql mysqlのインストールディレクトリ、mysqlをサポートする。
--with-MySQLi=/usr/local/mysql/bin/mysql_config mysqli ファイルディレクトリ、最適化サポート
--enable-safe-mode セーフモードをオンにします。

--enable-ftp ftp のサポートをオンにします。
--enable-zip zip のサポートをオンにします。
--with-bz2 bz2ファイルのサポートをオンにします。                       
--with-jpeg-dir jpeg 画像のサポートを有効にします。
--with-png-dir png 画像のサポートをオンにします。
--with-freetype-dir freetypeフォントライブラリのサポートをオンにします。
--without-iconv は、文字セット間の変換を行う iconv 機能をオフにします。
--with-libXML-dir libxml2 ライブラリのサポートを有効にします。
--with-XMLrpc は xml-rpc のための c を有効にします。
--with-zlib-dir zlibライブラリのサポートをオンにします。
--with-gd は gd ライブラリのサポートを有効にします。
--enable-gd-native-ttf は TrueType 文字列ライブラリをサポートします。
--with-curl は、curl ブラウジングツールのサポートを有効にします。
--with-curlwrappers url ストリームを curl ツールでオープンする。
--with-ttf は freetype1.* のサポートを有効にしますが、これは省略可能です。
--libXML2 ライブラリを拡張し、libxslt ソフトウェアを必要とします。
--with-gettext は gnu の gettext サポートを有効にします。これはエンコーディングライブラリで使用されます。
--with-pear PHP 拡張モジュールが使用する pear コマンドのサポートを有効にします。
--enable-calendar カレンダー拡張機能をオンにします。
--enable-mbstring マルチバイト、文字列のサポート
--enable-bcmath 画像のリサイズを有効にする(zabbix の監視で使用)。
--enable-sockets ソケットのサポートを有効にします。
--enable-exif メタデータのサポート(画像用
--enable-magic-quotes magic-quotes をサポートします。
--disable-rpath 追加のランタイムライブラリファイルを無効にします。
-disable-debugはデバッグモードをオフにします。
--with-mime-magic=/usr/share/file/magic.mime マジックヘッダーファイルの場所

<スパン --enable-opcache // PHP5.5 X + 新しいコードアクセラレーション機能
<スパン CGIインストール時のみのパラメータ
--enable-fpm このパラメータは、PHP-fpm パッチが適用され、CGI によるインストール方法でプログラムを起動した後でのみ使用可能です。
--enable-fastCGI PHP の起動方法として fastcgi をサポートします。
--enable-force-CGI-redirect 上記と同じですが、ヘルプには説明がありません。
--with-ncurses ncurses による画面描画とテキストベースの端末グラフィカルインタラクションをサポートする動的なライブラリ
--enable-pcntl freeTDS に必要、おそらく mssql にリンクするため。
mhash と mcrypt アルゴリズムの拡張機能
with-mcryptアルゴリズム
with-mhash アルゴリズム
--with-gmp
--enable-inline-optimization
--with-openssl openssl をサポート、暗号化された転送に使用されます。
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config perlの通常のライブラリケースのインストール先です。
-disable-dmalloc
--with-gdbm dba の gdbm サポートです。
--sigchild を有効にする
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte zend のマルチバイトをサポートします。
--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap


<スパン 準備 PHP の設定ファイルは

<テーブル
1
2
# cd /home/down/php-
5.
5
.
11
# cp php.ini-production /usr/local/php/etc/php.ini

<スパン 準備 php_fpm の設定ファイルです。

<テーブル
1
2
3
4
# cd /usr/local/php/etc/
# cp php-fpm.conf.
default
php-fpm.conf
# vim php-fpm.conf

<スパン php-fpm.confの設定を変更します。 ファイル 以下の内容の前のセミコロンを削除し、実際のハードウェア構成に応じて変更します。

ここでは簡単な設定のみを行い、PHP-FPMの詳細な最適化設定については後ほど説明します。

ダイナミックモードの場合  pm.start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pid = run/php-fpm.pid
error_log = log/php-fpm.log
リッスン =  127.0 . 0.1 : 9000
pm.max_children = 40
pm.start_servers = 12    (pm.start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2)
pm.min_spare_servers = 4


pm.max_spare_servers = 20


pm.max_requests = 1000

<スパン <スパン <スパン php-fpmでphpを起動する ( 注意すべきは、起動時に 構成 ファイルは、ユーザーグループ + に与える必要があります。 rx パーミッション 具体的には、サーバーのアイテムに +x パーミッション、そうでない場合は に実行可能なパーミッションがないために生成されました。 例外エラー )

Php-fpmのコード

php5.5X+版では、php-fpmの管理ツールを提供し、起動・停止・再起動が簡単にできるようになりました。

Php-fpmのコード  

  1. // 個人的には、ここにphp関連のコマンドを放り込んでました  

  2. #cd /usr/local/php/sbin/  

  3. // このファイルをインストールファイル内にコピーする  

  4. #cp /home/down/php-5.5.11/sapi/fpm/init.d.php-fpm . /  

  5. #chmod 755 init.d.php-fpm  

  6. // スタート|ストップ|リスタート  

  7. #. /init.d.php-fpm start 

PHP-FPMを起動するもう一つの方法 : その

php/php-fpmが正常にインストールされているかどうかテストします。 :

#
Testing php-fpm
Configuration (the actual path is replaced by your own PHP installation path)
/usr/local/php/sbin/php-fpm
-t
/usr/local/php/sbin/php-fpm
-c
/usr/local/php/etc/php
.ini -y
/usr/local/php/etc/php-fpm
.conf -t

A message like the following proves that the test passed and PHP/php-fpm was installed successfully
[18-Apr-2014 23:20:15] NOTICE: 設定ファイル /usr/local/php/etc/php-fpm.conf のテストが成功しました。

(ちょっとしたハプニング:初めてテストした時、起動時に以下のエラーが出たので、vim /usr/local/php/etc/php-fpm.conf を開き、52行目までのコメントセミコロン ";" を付け忘れたことが判明、OK修正しました!。

php-fpm の起動 [18-Apr-2014 23:09:15] ERROR: [/usr/local/php/etc/php-fpm.conf:52] 値が ZEND_INI_PARSER_ENTRY で NULL です。
[18-Apr-2014 23:09:15] ERROR: 設定ファイル '/usr/local/php/etc/php-fpm.conf' の読み込みに失敗しました。
[18-Apr-2014 23:09:15] ERROR: FPMの初期化に失敗しました)

#
Start php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm
-c
/usr/local/php/etc/php
.ini -y
/usr/local/php/etc/php-fpm
.conf
#
Close php-fpm
kill
-INT `
cat
/usr/local/php/var/run/php-fpm
.pid`
#
Restarting php-fpm
kill
-USR2 `
cat
/usr/local/php/var/run/php-fpm
.pid`

について php-fpm 提供する Sysv init スクリプトを作成し、サービスリストに追加して、起動時に自動的に開始するようにします。

<テーブル
1
2
3
4
5
6
# cd
/
home
/down/
php-
5.
5.11
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# cp sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on

<スパン コマンドラインから上記のようにすると、service php-fpm start を使用することができます。 | php-fpmを起動|停止|再起動します。

php-fpm.conf 重要なパラメータの詳細

pid = run
/php-fpm
.pid
#pid setting, default is var/run/php-fpm.pid in the installation directory, we recommend turning it on
error_log = log
/php-fpm
.log
#Error log, default is var/log/php-fpm.log in the installation directory
log_level = notice
# Error levels. The available levels are: alert (must be handled immediately), error (error condition), warning (warning condition), notice (general important information), debug (debug information). Default: notice.
emergency_restart_threshold = 60
emergency_restart_interval = 60s
# indicates that if the number of php-cgi processes with SIGSEGV or SIGBUS errors exceeds the emergency_restart_threshold within the value set by emergency_restart_interval, php-fpm will restart gracefully. These two options are generally left at their default values.
process_control_timeout = 0
# Set the timeout for child processes to accept multiplexing signals from the master process. Available units: s(seconds), m(minutes), h(hours), or d(days) Default unit: s(seconds). Default value: 0.
daemonize = 
yes
#In FPM, you can use different settings to run multiple process pools. These settings can be set individually for each process pool.

listen = 127.0.0.1:9000
#fpm listen port, i.e. the address where php is processed in nginx, usually the default value is sufficient. Available formats are: 'ip:port', 'port', '/path/to/unix/socket'. This needs to be set for each process pool.
listen.backlog = -1
#backlog number, -1 means no limit, determined by OS, just comment out this line. backlog meaning refer to: http://www.3gyou.cc/?p=41
listen.allowed_clients = 127.0.0.1
#The default value is any. Each address is separated by a comma. If it is not set or is empty, any server will be allowed to request a connection
listen.owner = www
listen.group = www
listen.mode = 0666
#unix socket setup options, if using tcp access, just comment here.
user = www
group = www
# accounts and groups that start processes
pm = dynamic 
# For dedicated servers, pm can be set to static.
#If you choose static, the number of child processes is fixed by pm.max_children. If you choose dynamic, the number of children is determined by the following parameters.
# pm.start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.max_children 
#, maximum number of child processes
pm.start_servers
#, number of processes at startup
pm.min_spare_servers
#, guarantee minimum number of idle processes, create new child processes if idle processes are less than this value
pm.max_spare_servers
#, guarantee the maximum number of idle processes, if idle processes are greater than this value, this will be cleaned up
pm.max_requests = 1000
# Set the number of requests to serve before each child process respawns. Useful for third-party modules that may have memory leaks. If set to '0', requests are always accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.
pm.status_path =
/status
The URL of the #FPM status page. If not set, the status page will not be accessible. Default value: none. munin monitoring will use the
ping
.path =
/ping
The ping URL for the #FPM monitoring page. If this is not set, the ping page will not be accessible. This page is used externally to check if the FPM is alive and ready to respond to requests. Please note that it must start with a slash (/).
ping
.response = pong
# is used to define the ping request return. Returns a text/plain formatted text for HTTP 200. Default value: pong.
request_terminate_timeout = 0
# Set the timeout for individual requests. This option may be useful for scripts where the 'max_execution_time' setting in php.ini does not abort for some specific reason. A setting of '0' means 'Off'. Try changing this option when there are frequent 502 errors.
request_slowlog_timeout = 10s
# When a request has a set timeout, the corresponding PHP call stack information is written to the slowlog in full. Set to '0' for 'Off'
slowlog = log/$pool.log.slow
#Logging of slow requests, used in conjunction with request_slowlog_timeout
rlimit_files = 1024
# Set the rlimit limit for file open descriptors. Default: The default system-defined value for openable handles is 1024, which can be changed using ulimit -n to see, ulimit -n 2048.
rlimit_core = 0
# Set the maximum core rlimit limit value. Available values: 'unlimited', 0 or positive integer. Default value: system-defined value.
chroot =
# Chroot directory at startup. The defined directory needs to be an absolute path. If it is not set, the chroot will not be used.
chdir =
# Set the startup directory, which will be automatically chdir'd on startup. The defined directory needs to be an absolute path. Default: current directory, or /directory (when chroot)
catch_workers_output =
yes
# Redirect stdout and stderr to the main error log file during runtime. If not set, stdout and stderr will be redirected to /dev/null according to FastCGI rules. Default value: null.

PHP-FPMのよくあるエラーと対処法

file_get_contents が応答が遅すぎるリモートリソースを要求した場合、file_get_contents はタイムアウトせずにそこで立ち往生し続けます。php.ini の max_execution_time が PHP スクリプトの最大実行時間を設定することは知っていますが パラメータは、php-cgi (php-fpm) では動作しません。PHP スクリプトの最大実行時間を実際に制御するのは、php-fpm.conf 設定ファイルにある request_terminate_timeout パラメータです。

request_terminate_timeoutのデフォルト値は0秒で、これはPHPスクリプトが実行され続けることを意味します。したがって、全てのphp-cgiプロセスがfile_get_contents()関数で停止した場合、Nginx+PHP WebServerは新しいPHPリクエストを処理できなくなり、Nginxはユーザに "502 Bad Gateway" を返します。PHPスクリプトの最大実行時間を設定するためにこのパラメータを修正することは必要ですが、治療法ではありません。例えば30秒に変更した場合、file_get_contents()がページの内容を取得するのが遅い場合、150のphp-cgiプロセスが1秒間に5つのリクエストしか処理できないことになり、WebServerも "502 Bad Gateway" を回避することが難しくなってしまいます。 解決策としては、request_terminate_timeoutを10秒または妥当な値に設定するか、file_get_contentsにタイムアウトパラメータを追加することです。

<テーブル
1
2
3
4
5
6
7
 $ctx
= stream_context_create(
array
(
'http'
=>
array
(
'timeout'
=> 10   
// Set a timeout in seconds
)
 ));
 file_get_contents
(
$str
, 0,
$ctx
);

2,max_requestsパラメータの設定が適切でない場合、断続的に502エラーが発生することがあります。

<テーブル