Project

General

Profile

Load balancing with FastCGI/PHP

Added by over 14 years ago

Hi there,

How do I configure load balancing for FastCGI/PHP?

I have three lighttpd servers. The main server accepts requests and delegates the requests to either Server1 or Server2. The problem is that the main server is always throwing 500 Internal Error.

Main Server's Log:

2010-11-29 23:33:46: (log.c.166) server started
2010-11-29 23:33:57: (mod_fastcgi.c.3061) got proc: pid: 0 socket: tcp:127.0.0.1:82 load: 1
2010-11-29 23:34:57: (mod_fastcgi.c.2568) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:82
2010-11-29 23:34:57: (mod_fastcgi.c.3356) response not received, request sent: 913 on socket: tcp:127.0.0.1:82 for /index.php?, closing connection
2010-11-29 23:34:57: (mod_fastcgi.c.1492) released proc: pid: 0 socket: tcp:127.0.0.1:82 load: 0

Server1's Log:

2010-11-29 23:33:27: (log.c.166) server started
2010-11-29 23:33:27: (mod_fastcgi.c.1367) --- fastcgi spawning local
        proc: /usr/bin/php-cgi
        port: 0
        socket /tmp/php-fastcgi-server1.socket
        max-procs: 4
2010-11-29 23:33:27: (mod_fastcgi.c.1391) --- fastcgi spawning
        port: 0
        socket /tmp/php-fastcgi-server1.socket
        current: 0 / 4
2010-11-29 23:33:27: (mod_fastcgi.c.1391) --- fastcgi spawning
        port: 0
        socket /tmp/php-fastcgi-server1.socket
        current: 1 / 4
2010-11-29 23:33:27: (mod_fastcgi.c.1391) --- fastcgi spawning
        port: 0
        socket /tmp/php-fastcgi-server1.socket
        current: 2 / 4
2010-11-29 23:33:27: (mod_fastcgi.c.1391) --- fastcgi spawning
        port: 0
        socket /tmp/php-fastcgi-server1.socket
        current: 3 / 4
2010-11-29 23:33:50: (mod_fastcgi.c.3061) got proc: pid: 5225 socket: unix:/tmp/php-fastcgi-server1.socket-3 load: 1
2010-11-29 23:33:50: (mod_fastcgi.c.1492) released proc: pid: 5225 socket: unix:/tmp/php-fastcgi-server1.socket-3 load: 0

Main Server's Config:

server.port = 81
server.username = "www_user" 
server.groupname = "www" 

#accesslog.filename = "/usr/webdoc/logs/main82.log" 
#server.errorlog = "/usr/webdoc/logs/main82_err.log" 

# mimetype mapping

mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar" 
)
server.document-root = "/usr/webdoc/jidris.ath.cx" 
server.modules = ("mod_rewrite", "mod_redirect", "mod_alias", "mod_access", "mod_auth", "mod_fastcgi", "mod_cgi", "mod_accesslog", "mod_compress")

index-file.names = ("index.html", "index.php")

fastcgi.debug = 1
fastcgi.server = (".php" =>
            ((
                "host" => "127.0.0.1",
                "port" => 82,
                "check-local" => "disable",
                "doc-root" => "/usr/webdoc/server1" 
            ))
        )

Server1's Config

server.port = 82
server.username = "www_user" 
server.groupname = "www" 

server.document-root = "/usr/webdoc/server1" 

#accesslog.filename = "/usr/webdoc/logs/server1.log" 
#server.errorlog = "/usr/webdoc/logs/server1_err.log" 

server.modules = ("mod_fastcgi")

# mimetype mapping
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar" 
)

index-file.names = ("index.html", "index.php")

fastcgi.debug = 1
fastcgi.server = (".php" => ((
                   "bin-path" => "/usr/bin/php-cgi",
                   "bin-environment" => (
                           "PHP_FCGI_CHILDREN" => "5",
                           "PHP_FCGI_MAX_REQUESTS" => "1000" 
                       ),
                   "min-procs" => 2,
                   "max-procs" => 4,
                   "socket" => "/tmp/php-fastcgi-server1.socket" 
                 )))

Server2's config

server.port = 83
server.username = "www_user" 
server.groupname = "www" 

server.document-root = "/usr/webdoc/server2" 

#accesslog.filename = "/usr/webdoc/logs/server2.log" 
#server.errorlog = "/usr/webdoc/logs/server2_err.log" 

server.modules = ("mod_fastcgi")

# mimetype mapping
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar" 
)

index-file.names = ("index.html", "index.php")

fastcgi.debug = 1
fastcgi.server = (".php" => ((
                   "bin-path" => "/usr/bin/php-cgi",
                   "bin-environment" => (
                           "PHP_FCGI_CHILDREN" => "5",
                           "PHP_FCGI_MAX_REQUESTS" => "1000" 
                       ),
                   "min-procs" => 2,
                   "max-procs" => 4,
                   "socket" => "/tmp/php-fastcgi-server2.socket" 
                 )))


Regards,


Replies (2)

RE: Load balancing with FastCGI/PHP - Added by stbuehler over 14 years ago

lighttpd is a FastCGI client, not a FastCGI server. use mod_proxy.

RE: Load balancing with FastCGI/PHP - Added by over 14 years ago

How do I go about setting up a FastCGI server? Are there any compiled implementations around?
I did a bit of googling and didn't find much on setting up a fastcgi server.

All I got is info on how to write a loop to accept FastCGI requests.

    (1-2/2)