php file_get_contents 执行两次

标签 php file-get-contents

我已经创建了一个脚本来将备份磁带 checkin 我们的磁带库并使用 TSM checkin 它们。此脚本由短信激活。

我们的 SMS 服务器接收开始 checkin 的命令,然后使用 file_get_contents 命令在 TSM 服务器上执行脚本。

我有一个问题,当有分配的磁带要 checkin (+20) 时,脚本被执行了两次。这会导致 TSM 服务器出错,因为移动媒体命令都是双倍的。

我通过在第一个 file_get_content 启动时放入一个初始时间戳记录来克服这个问题,这样命令就不会执行两次。虽然这修复了双命令问题,但它仍然存在问题,因为 SMS 服务器发回确认脚本是否启动。所以这意味着每次使用 +20 个磁带进行 checkin 时,运算符(operator)都会收到 2 条消息,其中一条表示 checkin 失败,另一条 checkin 开始。

我怀疑这是因为将命令传递到 TSM 服务器所花费的时间(最多可能需要 45 秒)。

长话短说,有没有办法可以设置某种更长的超时,或者提供任何参数/检查来防止这种行为?提前致谢。路径由 ***** 替换。

SMS server code
    //DRM checkin
            if($auth == 1 AND strtolower($sms_body) == "******"){
                $knowncommand = 1;
                $url = "http://*******/******/checkin.php?remote&exec&sender=" . $from;
                $dodrm = file_get_contents($url);
                if ($stmt2 = $mysqli->prepare("UPDATE messagein SET checked = 1 WHERE checked = 0 ")) {
                    $stmt2->execute();
                    $stmt2->close();
                }
            }

TSM 服务器脚本代码:

if(isset($_GET['exec'])){
    if(isset($_GET['remote'])){
        $rcs = CheckRemoteCheckinStatus();
        $to = $_GET['sender'];
        //Execute drm check-in
        $commit = CheckButtonStatus();
        if($commit == "" AND $rcs == 0){
            SetRemoteCheckinStatus();
            $psDIR = "*****";
            $psScript = "drm_checkin_retrieve.ps1";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
            SetCheckinStatus();
            $psDIR = "*****";
            $psScript = "QueueSMS.ps1 $to 'Check-in gestart...'";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
        }
        else{
            //Send Failed SMS
            $psDIR = "*****";
            $psScript = "QueueSMS.ps1 $to 'Fout: Geen Check-in mogelijk.'";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
        }
    }
    else{
        $psDIR = "*******";
        $psScript = "drm_checkin_retrieve.ps1";
        $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
        exec($runCMD, $out);
        echo "Check-in gestart...<br><br>";
        SetCheckinStatus();
    }
}

最佳答案

如果您有权访问您的 php.ini,这 topic可能会有用

如果你只想增加特定脚本的超时时间,你可以使用 set_time_limit

或者换一种方式,在你的 php 脚本的开头:

ini_set('max_execution_time', 120); //120 seconds

关于php file_get_contents 执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38830173/

相关文章:

php - MySQL准备和执行的问题

php - 将数据从一个表复制到另一个表的最佳方法

php - 使用 PHP 将 mySQL 表转换为带有子数组的 JSON 数组

regex - 在两个字符串Powershell之间替换文本

php - 从php页面获取HTML数据

php - 文件获取内容或 fsockopen - 超时问题

php - HTTP 请求失败! HTTP/1.1 505 HTTP 版本不受支持错误

php - 创建复选框以更改输出文本颜色

php - 通过基于重定向的身份验证收到的 token 是否预期是长期存在的 token

soap - PHP : What is fastest SOAP, file_get_contents 或 Curl?