0

I am running a PHP application on nginx with HHVM as main and PHP-FPM as backup

This is my config of nginx regarding the php processing

  location ~ \.(hh|php)$ {
    fastcgi_intercept_errors on;
    error_page 500 501 502 503 = @fallback;

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_keep_conn on;

    include         fastcgi_params;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param   SERVER_NAME $host;
    fastcgi_pass    127.0.0.1:9000;
  }

  location @fallback {

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    include         fastcgi_params;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param   SERVER_NAME $host;
    fastcgi_pass    unix:/var/run/php5-fpm.sock;

  }

To test the config,I stopped the hhvm service.Normally that would pass the request to PHP-FPM and should return 200 but I am getting 502 error as follows :

12296#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.34.235, server: stylep3.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host:localhost

Am I doing anything wrong here

0

I found that hhvm includes hhvm.conf in the default vhost file of nginx.

That is processing the request and sending the error.

I modified the config to

upstream php_backend {
  server 127.0.0.1:9000;
  server unix:/var/run/php5-fpm.sock backup;
}


server {
#
# other conf...
#

 location ~ \.(hh|php)$ {
    fastcgi_intercept_errors on;

    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_keep_conn on;

    include         fastcgi_params;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param   SERVER_NAME $host;
    fastcgi_pass    php_backend;
  }

}

and removed the line

include hhvm.conf

from vhost file.

That solved the issue!

  • your first config works perfect, BUT your config only good when hhvm and php-fpm on different servers, so what is the point to run them both locally?? and in case of php error every backend will fail anyway.... – ADM Oct 3 '15 at 14:47
  • No,when hhvm processor takes too much load and stops abruptly the php-fpm process takes charge and starts processing the request. I am running both things on the same server as of now. we are facing scaling issues as of now.So,I heard hhvm is fast after initial JIT warmup.So iam setting up with fallback. – 5ud0 Oct 3 '15 at 17:52
  • install varnish then. if all load will be forwarded from hhvm to php-fpm your server will die in agony..., . hhvm is a single process, php-fpm will be forked into hundreds of child processes. think about cache in front. – ADM Oct 3 '15 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.