Welcome! Log In Create A New Profile

Advanced

PHP CGI keeps crushing

Posted by jorjica1 
PHP CGI keeps crushing
July 22, 2009 06:58AM
Hello all

I have a small vps from slicehost.
I've setup nginx with fastcgi as a webserver for a few of my domains.
My problem is that after a few requests is just...crushes. I can see that is still uses CPU...but it just not responding and after 60 seconds it throws a 402 or 504 header on every vhost.
I use fedora core 10 and nginx was installed using yum.
Here is my nginx -V output:
nginx version: nginx/0.6.35
built by gcc 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)
configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cc-opt=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic --add-module=/builddir/build/BUILD/nginx-0.6.35/nginx-upstream-fair

And here is my script that starts php-cgi:
#!/bin/sh
# NGINX FastCGI php5 startup shell script
# Feedback <vivek@nixcraft.com>
# http://bash.cyberciti.biz/web-server/fastcgi-php-server-start-stop-script/
# Set ME #
PROVIDES=php-cgi
LIGHTTPD_FCGI=/usr/bin/spawn-fcgi
SERVER_IP=127.0.0.1
SERVER_PORT=9000
SERVER_USER=nginx
SERVER_GROUP=nginx
PHP_CGI=/usr/bin/php-cgi
PGREP=/usr/bin/pgrep
KILLALL=/usr/bin/killall
PHP_FCGI_CHILDREN=32 //or 5 or 16 - the same result
PHP_FCGI_MAX_REQUESTS=10000 //or 1000 - the same result

export PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS

### No editing below ####
cmd=$1

pcgi_start(){
echo "Starting $PROVIDES..."
$LIGHTTPD_FCGI -a $SERVER_IP -p $SERVER_PORT -u $SERVER_USER -g $SERVER_GROUP -f $PHP_CGI -C $PHP_FCGI_CHILDREN
}

pcgi_stop(){
echo "Killing $PROVIDES..."
$KILLALL $PROVIDES
}

pcgi_restart(){
pcgi_stop
pcgi_start
}

pcgi_status(){
$PGREP $PROVIDES > /dev/null
[ $? -eq 0 ] && echo "$PROVIDES running" || echo "$PROVIDES NOT running"

}

pcgi_help(){
echo "Usage: $0 {start|stop|restart|status}"
}

case ${cmd} in
[Ss][Tt][Aa][Rr][Tt]) pcgi_start;;
[Ss][Tt][Oo][Pp]) pcgi_stop;;
[Rr][Ee][Ss][Tt][Aa][Rr][Tt]) pcgi_restart;;
[Ss][Tt][Aa][Tt][Uu][Ss]) pcgi_status ;;
*) pcgi_help ;;
esac


And my nginx.conf:

..come comments
user nginx;
worker_processes 5;

error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

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

log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
....

And in a vhost setup the php script is called like this:

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}



and finnaly my fastcgi_params:

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;


What can I try to do?


Thnks
George Cotinghiu
Re: PHP CGI keeps crushing
July 23, 2009 08:56PM
What is crashing? Is it the php-cgi processes? What do the logs show?

If it's php, you might consider using php-fpm to control your php processes. Many people have better luck with it.

Separate issue but you have far too many worker processes for a small VPS, unless you have access to five CPU cores, and even then, one or two will be enough.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 107
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready