- apache — PHP Bad File Descriptor Error
- Answer
- Solution:
- Answer
- Solution:
- Answer
- Solution:
- Answer
- Solution:
- Share solution ↓
- Additional Information:
- Didn’t find the answer?
- Similar questions
- Write quick answer
- About the technologies asked in this question
- PHP
- Laravel
- Welcome to programmierfrage.com
- Get answers to specific questions
- Help Others Solve Their Issues
- Bad file descriptor php
apache — PHP Bad File Descriptor Error
We’ve recently upgraded our servers from PHP 5.4.15 to 5.5.1 and have started getting this error in the logs
Fatal Error Unable to create lock file: Bad file descriptor
I’ve tracked it down to this bit a code that opens another small PHP script which uploads a file to S3 in the background.
// Grab uploaded file and assign a working name $fileTemp = $_FILES['file']['tmp_name']; $pathToWorkingFile = tempnam($g_TmpDirectory, "TR-"); // Move the file to our working area if (move_uploaded_file($fileTemp, $pathToWorkingFile) === false) throw new Exception("Cannot move file to staging area.", 1011); // Where the file will end up on S3 $s3Bucket = "test.bucket.com"; $uploadDest = "/uploads/image123.jpg"; // Create process to upload file in background popen("/usr/local/bin/php /path/to/uploadScript.php $pathToWorkingFile $s3Bucket $uploadDest &", 'r');
Answer
Solution:
It turns out that this error was caused by our configuration of OPcache which was enabled during the PHP upgrade process. When I disable it for command line operations by removing this setting from php.ini everything works fine.
opcache.enable_cli=1
Answer
Solution:
I was able to resolve with opcache.enable_cli=1 , but for me the underlying problem was wrong permissions on the /tmp directory in MacOS.
This is what I did to fix this:
sudo rm -Rf /tmp sudo rm -Rf /private/tmp sudo mkdir /private/tmp sudo chown root:wheel /private/tmp sudo chmod 1777 /private/tmp sudo ln -s /private/tmp /tmp
Answer
Solution:
If you are on Ubuntu your /tmp permissions are off.
Running this fixed it for me when trying to run php artisan serve for laravel.
See the original post here:
Answer
Solution:
I got the Bad file descriptor in php-cli in Windows because I had the Controlled folder access setting turned on in Windows Security в†’ Virus & threat protection в†’ Ransomware Protection.
When I was trying to run composer from the command line, it wasn’t able to initialise, and gave the error —
[ErrorException] file_put_contents(): Write of 111 bytes failed with errno=9 Bad file descriptor
Surprisingly, Windows Security’s blocked app notification didn’t appear at all. But when I manually went to Allow an app through controlled folder access в†’ Add an allowed app and selected the php.exe executable, composer started working.
Share solution ↓
Additional Information:
Didn’t find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor — hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.
Bad file descriptor php
Due to the needs of the company’s development department, it is now necessary to use php-5.4.17, download, install, and configure according to the convention. But after configuring it, restart php-fpm multiple times and find that there are a lot of the following error messages in php-fpm.log:
[24-Aug-2013 04:29:05] ERROR: unable to read what child say: Bad file descriptor (9) [24-Aug-2013 04:29:05] ERROR: unable to read what child say: Bad file descriptor (9) [24-Aug-2013 04:29:05] ERROR: unable to read what child say: Bad file descriptor (9) [24-Aug-2013 04:29:05] ERROR: unable to read what child say: Bad file descriptor (9) [24-Aug-2013 04:29:05] ERROR: unable to read what child say: Bad file descriptor (9)
It’s weird, there’s nothing special about the configuration, it’s the same as the old version!
The contents of the configuration file are as follows:
[global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice daemonize = yes rlimit_files = 65536 [www] user = daemon group = daemon listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 pm = static pm.max_children = 128 pm.max_requests = 500 pm.status_path = /status ping.path = /ping ping.response = pong slowlog = var/log/$pool.log.slow request_slowlog_timeout = 2s request_terminate_timeout = 15s rlimit_files = 65536 catch_workers_output = yes php_flag[display_errors] = on
Later found that it is caused by catch_workers_output = yes, it is good to change yes to no, no error.
But this function is exactly what I need, so I think this should be a bug in php-5.4.17. Finally, I don’t need this version, I used php-5.3.27.
Compile and install the same method as php-5.4.17, repeated restarts or the same error as php-5.4.17, it is a hell.
Start google, and finally found the problem, it is indeed a bug.
You can see that there are three versions with this bug: 5.3.27, 5.4.17, 5.5.1.
The solution is also there, a patch is provided below the bug page, and the patch is ok, the specific operation is as follows:
wget -O fpm-race-condition.patch 'https://bugs.php.net/patch-display.php?bug_id=65398&patch=fpm-race-condition.patch&revision=1375772074&download=1'
Recompile and install. This time, catch_workers_output = yes is turned on, and again and again, the error no longer occurs.