wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to fix “Error: unable to read what child say: bad file descriptor”

by | Dec 2, 2018

Website errors can be frustrating, especially if they are cryptic, like “Error: unable to read what child say: bad file descriptor“.

You know that there is an error but where?

Here at Bobcares, we help website owners to resolve such complex errors as part of our Support Engineers services.

Today, let’s see the top 3 reasons for this error and how we fix them.

 

What is “Error: unable to read what child say: bad file descriptor”?

It’s true that Nginx and PHP-FPM combo is a better option for handling a large number of requests.

This is because, Nginx requires significantly less memory per connection, and PHP-FPM dramatically speeds up the performance of your PHP environment.

But, if you have a busy server, sometimes PHP-PFM may crash out.

As a result, users experience website errors, like ‘502 bad gateway’ or ‘503 Service temporary unavailable’ in their web browsers.

Here, we check the error logs(/var/log/phpX-fpm.log or /var/log/plesk-phpXX-fpm/error.log, where X is the PHP version) to get the detailed error message.

For instance, in Plesk servers, the error looks like this:

ERROR: unable to read what child say: Bad file descriptor (9)

 

Now, let’s discuss the 2 main causes of this error and how our Support Engineers fix them.

 

“Error: unable to read what child say: bad file descriptor” – Causes & Fixes!

In our experience handling website issues, we found 3 main reasons for this “Error: unable to read what child say: bad file descriptor”.

 

1) Service downtime

Sometimes, unexpected service crashes can lead to this error.

PHP-FPM is an alternate FastCGI service that allows a website to handle heavy loads.

But, this service may fail due to traffic spikes, resource limits, disk errors, DDOS attack, etc.

 

How we fix?

Firstly, we check the status of php-fpm service.

For instance, in Plesk servers, we check the service status as below. Here X is the PHP version.

service plesk-phpXX-fpm status

 

If there is a failed or unresponsive service, our primary focus is to figure out the problem and fix the service.

This is done with the help of application, service and website logs.

 

2) PHP-FPM configuration issues

PHP-FPM has a lot of configuration parameters which determine the way it performs.

These parameters have to be determined based on the available server resources like RAM, CPU, etc.

The php-fpm configuration file /etc/php-fpm.conf or /etc/php-fpm.d/[domain.com].conf looks like this:

pm = ondemand
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 150

 

But, in the below scenarios, this default setting doesn’t work and php-fpm reaches max_children.

  • Lot of concurrent visitors to the website.
  • Buggy PHP scripts in the website.
  • Slow execution of PHP scripts due to server resources.

 

Result is “Error: unable to read what child say: bad file descriptor”.

 

How we fix?

The solution is to tweak these PHP-FPM settings based on available server resources. Otherwise, the server may crash.

Therefore, our Support Engineers first check available server resources, website traffic, website contents and then fine tune these values.

Also, in a server with multiple services, all of them are taken into account while tuning these parameters.

Let’s see how we tweak these values in a Plesk server.

 

a) First, we create/edit the custom php.ini file in the domain config directory “/var/www/vhosts/system/domain.com/conf/“.

b) Further, we tweak the following php-fpm parameters and add them to the above file.

pm.max_children = 40
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 8
pm.max_requests = 600

 

c) Now, we update the new PHP settings in PHP configuration file with the following command:

/usr/local/psa/bin/php_settings -u

 

d) Then, recompile the domain settings with the following command:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com

 

e) Finally, restart the php-fpm service with the following command:

service plesk-phpXX-fpm restart

 

3) PHP bug

PHP-FPM has worker processes that handles the PHP requests.

We’ve seen users enable catch_workers_output in the PHP-FPM configuration to allow error logging for these worker processes.

Sometimes, it conflicts with the PHP versions and leads to “Error: unable to read what child say: bad file descriptor”.

 

How we fix?

PHP has officially declared this as a bug, affecting versions 5.3.27, 5.4.17, 5.5.1.

So, first we try to upgrade the PHP version of the website to PHP 7, as it makes the website faster and secure.

However, sometimes the website settings may not be compatible with the new PHP version.

Therefore, before upgrading, we first check the compatibility of the website with the new PHP version.

If upgrade is not possible, we’ll download and apply the patch “fpm-race-condition.patch” released by PHP.

 

Conclusion

In short, Error: unable to read what child say: bad file descriptor can occur due to service downtime, php-fpm configuration issues, etc. Today, we’ve discussed the top 3 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Categories

Tags