【问题标题】:PHP Bad File Descriptor ErrorPHP 错误文件描述符错误
【发布时间】:2013-07-29 20:47:03
【问题描述】:

我们最近将服务器从 PHP 5.4.15 升级到 5.5.1,并开始在日志中出现此错误

致命错误无法创建锁定文件:文件描述符错误

我已经追踪到这一点,一个代码打开了另一个小的 PHP 脚本,该脚本在后台将文件上传到 S3。

// 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');

【问题讨论】:

  • 我们不知道你的代码的其余部分是什么样的......那个 sn-p 似乎没什么用......
  • 我希望至少$SOME $ARGUMENTS得到escapeshellarg()的治疗。
  • 可能是文件系统损坏,测试和修复取决于您的操作系统。 fsck 是在 linux 上启动或在 windows 上扫描/检查磁盘的地方
  • 跳出来的一件事是您尝试从您在后台中运行的进程中读取
  • @JaredD 我鼓励您在“答案”框中发布您的解决方案。

标签: php apache


【解决方案1】:

事实证明,这个错误是由我们在 PHP 升级过程中启用的 OPcache 配置引起的。当我通过从 php.ini 中删除此设置来禁用命令行操作时,一切正常。

opcache.enable_cli=1

【讨论】:

    【解决方案2】:

    我可以使用opcache.enable_cli=1 解决,但对我来说,根本问题是MacOS 中/tmp 目录的权限错误。

    这是我为解决这个问题所做的:

    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
    

    【讨论】:

    • 感谢您的快速解决方案。但是您的第 3 行可能不正确?在private/tmp/之前添加/
    【解决方案3】:

    如果您使用的是 Ubuntu,则您的 /tmp 权限处于关闭状态。

    当我尝试为 laravel 运行 php artisan serve 时,运行它为我解决了这个问题。

    运行:

    chmod 1777 /tmp

    您可能需要使用sudo

    在此处查看原始帖子:

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

    【讨论】:

      【解决方案4】:

      我在 Windows 的 php-cli 中获得了 Bad file descriptor,因为我在 Windows 安全 → 病毒和威胁防护 → 勒索软件防护中打开了 受控文件夹访问 设置.

      当我尝试从命令行运行 composer 时,它无法初始化,并给出了错误 -

      [ErrorException]
        file_put_contents(): Write of 111 bytes failed with errno=9 Bad file descriptor
      

      令人惊讶的是,Windows 安全中心的被阻止应用通知根本没有出现。但是当我手动转到通过受控文件夹访问允许应用程序添加允许的应用程序并选择php.exe可执行文件时,作曲家开始工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-08
        • 1970-01-01
        • 2017-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多