2

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');
8
  • We have no idea what the rest of your code looks like... That one snippet seems quite useless... Commented Jul 29, 2013 at 20:48
  • I hope that at least $SOME $ARGUMENTS are getting treatment from escapeshellarg(). Commented Jul 29, 2013 at 20:52
  • Possibly a corrupted file system, The testing and fix depends on your OS. fsck is a place to start on linux or scan/check disk on windows Commented Jul 29, 2013 at 20:54
  • One thing that jumps out is you try to read from a process that you run in the background? Commented Jul 29, 2013 at 20:57
  • 1
    @JaredD I encourage you to post your solution in the "Answer" box instead. Commented Jul 30, 2013 at 16:44

4 Answers 4

6

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
Sign up to request clarification or add additional context in comments.

Comments

5

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

1 Comment

thank you for quick solution. but your line 3 may be incorrect? add /before private/tmp/.
1

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 accessAdd an allowed app and selected the php.exe executable, composer started working.

Comments

0

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.

Run:

chmod 1777 /tmp

You may need to use sudo.

See the original post here:

https://unix.stackexchange.com/questions/71622/what-are-correct-permissions-for-tmp-i-unintentionally-set-it-all-public-recu

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.