How to connect to PHP-FPM directly to resolve issues with blank pages

Seeing blank pages when using Nginx and PHP-FPM can be frustrating. The following quick guide will show you how to connect to PHP-FPM directly so that you can determine if it is the reason for the blank pages.

I recommend trying some simple approaches first to see if the blank pages are caused by syntax errors or missing code/extensions. You can do this by checking your Nginx error logs and php error logs for clues and ensuring that PHP-FPM is up and running. If nothing obvious sticks out, then proceed with the guide.

In my case, my wordpress homepage and random pages where showing blank pages.

The nginx error log was showing

When I tried to request the website in chrome, it would crash and alert me to either wait or kill the page.

Using curl on the command line, I requested my homepage and the response code was 200 indicating success. However the response was truncated and this message displayed:

After combing through Nginx and PHP-FPM configuration options, testing PHP-FPM using sockets and TCP, the issue was unresolved.

The issue turned out to be a segfault in PHP when running the latest 7.0.6 version. That’s why some pages would work fine and some pages would return blank. After rolling back, the issue was resolved.

Nginx is also lenient with its response codes, in this case, since the PHP process ended abruptly, Nginx assumed it was successful and returned a 200 status code.

In the rest of this guide, I’ll show you how to test this yourself.

On Debian/Ubuntu, you will need to install the cgi-fcgi tool:

On RHEL/Centos, cgi-fcgi is included in the fcgi package

Now you can run the following bash script to call PHP-FPM directly:

This can be used to render a wordpress homepage directly using PHP-FPM.

You will need to update the path to your PHP-FPM socket, or if you use TCP, you will need to replace that line with the following:

If you need to pass in more fastcgi parameters, check the ones that Nginx uses. Here are the default parameters:

When I ran fcgi tool, I was able to see the segfault in PHP with the message:

This is a great way to test PHP in isolation and determine if Nginx or PHP-FPM is the cause of your blank pages.

2 thoughts on “How to connect to PHP-FPM directly to resolve issues with blank pages

Leave a Reply to PHP Annotated Monthly – May 2016 | PhpStorm Blog Cancel reply

Your email address will not be published. Required fields are marked *