PHP process to work after multiple / simultaneous requests in Ngnix

1

The problem

I created a process using PHP to work with Nginx like this:

@echo off
echo Starting PHP FastCGI...
set PATH=C:\nginx\php;%PATH%
C:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php\php.ini
pause

But if more than 500 requests occur simultaneously this process is terminated and does not issue any failure messages or anything of the sort. Note that the Ngnix process continues to work, only PHP to "work".

To be clearer, this problem occurs when I use ab to test the performance of the pages on a "ngnix" server, like this:

ab -n 1000 -c 10 http://127.0.0.1:8000/info.php

After running ab , I have the following result:

Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
apr_pollset_poll: The timeout specified has expired (70007)
Total of 503 requests completed

Then I will check the PHP process on the "CMD" screen and it has the following message:

Starting PHP FastCGI...
Pressione qualquer tecla para continuar. . .

Clearly, the "CMD" went to "PAUSE" because the PHP process ended.

What could be happening?

Follow my settings:

  • Ngnix 1.6.2
  • PHP 5.4.12

ngnix.conf :

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8000;
        server_name  localhost;

        root        html;

        location / {
            try_files $uri $uri/ /index.php;
            index  index.php index.html index.htm;
            autoindex on;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }

            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }
}

php.ini

[PHP]
engine=On
default_charset="UTF-8"
short_open_tag=Off
asp_tags=Off
precision=14
output_buffering=Off
zlib.output_compression=Off
implicit_flush=Off
unserialize_callback_func=
serialize_precision=17
disable_functions=
disable_classes=
zend.enable_gc=On
expose_php=Off
max_execution_time=60
max_input_time=60
memory_limit=128M
error_reporting=E_ALL|E_STRICT
display_errors=On
display_startup_errors=On
log_errors=On
log_errors_max_len=1024
ignore_repeated_errors=Off
ignore_repeated_source=Off
report_memleaks=On
track_errors=On
html_errors=On


variables_order="GPCS"
request_order="GP"
register_argc_argv=Off
auto_globals_jit=On
post_max_size=8M
auto_prepend_file=
auto_append_file=
default_mimetype="text/html"


doc_root=
user_dir=
extension_dir=C:/ngnix/php/ext/
enable_dl=Off
file_uploads=On
upload_tmp_dir=c:/ngnix/temp/
upload_max_filesize=20M
max_file_uploads=20
allow_url_fopen=Off
allow_url_include=Off
default_socket_timeout=30
include_path=.

extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_imap.dll
extension=php_intl.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_memcache.dll
extension=php_mongo.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_phalcon.dll

[CLI Server]
cli_server.color=On

[Date]
date.timezone=UTC

[Pdo_mysql]
pdo_mysql.cache_size=2000

pdo_mysql.default_socket=

[Phar]
phar.readonly=0

[mail function]
SMTP=localhost
smtp_port=25

mail.add_x_header=On


[SQL]
sql.safe_mode=Off

[ODBC]
odbc.allow_persistent=On
odbc.check_persistent=On
odbc.max_persistent=-1
odbc.max_links=-1
odbc.defaultlrl=4096
odbc.defaultbinmode=1

[Interbase]
ibase.allow_persistent=1
ibase.max_persistent=-1
ibase.max_links=-1
ibase.timestampformat="%Y-%m-%d %H:%M:%S"
ibase.dateformat="%Y-%m-%d"
ibase.timeformat="%H:%M:%S"

[MySQL]
mysql.allow_local_infile=On
mysql.allow_persistent=On
mysql.cache_size=2000
mysql.max_persistent=-1
mysql.max_links=-1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout=60
mysql.trace_mode=Off

[MySQLi]
mysqli.max_persistent=-1
mysqli.allow_persistent=On
mysqli.max_links=-1
mysqli.cache_size=2000
mysqli.default_port=3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect=Off

[mysqlnd]
mysqlnd.collect_statistics=On
mysqlnd.collect_memory_statistics=On

[PostgreSQL]
pgsql.allow_persistent=On
pgsql.auto_reset_persistent=Off
pgsql.max_persistent=-1
pgsql.max_links=-1
pgsql.ignore_notice=0
pgsql.log_notice=0

[Sybase-CT]
sybct.allow_persistent=On
sybct.max_persistent=-1
sybct.max_links=-1
sybct.min_server_severity=10
sybct.min_client_severity=10

[bcmath]
bcmath.scale=0

[Session]
session.save_handler=files
session.save_path=c:/nginx/temp
session.use_cookies=1
session.use_only_cookies=1
session.name=PHPSESSID
session.auto_start=0
session.cookie_lifetime=0
session.cookie_path=/
session.cookie_domain=
session.cookie_httponly=
session.serialize_handler=php
session.gc_probability=1
session.gc_divisor=1000
session.gc_maxlifetime=1440
session.bug_compat_42=On
session.bug_compat_warn=On
session.referer_check =
session.cache_limiter=nocache
session.cache_expire=180
session.use_trans_sid=0
session.hash_function=0
session.hash_bits_per_character=5
url_rewriter.tags="a=href,area=href,frame=src,input=src,form=fakeentry"


[MSSQL]
mssql.allow_persistent=On
mssql.max_persistent=-1
mssql.max_links=-1
mssql.min_error_severity=10
mssql.min_message_severity=10
mssql.compatability_mode=Off
mssql.secure_connection=Off


[Tidy]
tidy.clean_output=Off

[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="c:/nginx/temp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit=5

[ldap]
ldap.max_links=-1

[geoip]
geoip.custom_directory=c:/nginx/php/ext/
    
asked by anonymous 10.10.2014 / 20:56

1 answer

2

The pm.max_requests is usually set with a limit, because after reaching this limit there must be an event that restarts FastCGI, this is usually used to avoid memory leaks on servers (in a development environment you probably will not feel).

You can even set pm.max_requests to the needs of your server and to restart (in the case of Windows, we will hardly see Windows servers with Ngnix, the example is only for understanding how to restart PHP), you can create a loop with goto :

@echo off

echo Iniciando PHP FastCGI

:nginx_loop
echo Reiniciando...
set PATH=C:\nginx\php;%PATH%
C:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php\php.ini
goto nginx_loop

Each time the php-cgi.exe process is terminated, goto restarts it.

But on a development server, you do not need to limit pm.max_requests and create a loop, just put the limit as "zero" (note that on production servers this can cause memory leak).

  

The number of requests for each child process must be executed before each new run. This can be useful for circumventing memory failures of third-party libraries. For order processing not complete specify 0 . That is equivalent to PHP_FCGI_MAX_REQUESTS . Default value is 0

Source: link

An example would be to use set in a .bat file:

@echo off
echo Iniciando PHP FastCGI...
set PATH=C:\nginx\php;%PATH%
set PHP_FCGI_MAX_REQUESTS=0
C:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php\php.ini
pause
    
10.10.2014 / 23:45