Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP脚本在crontab中异常停止_Php_Mysql_Cron - Fatal编程技术网

PHP脚本在crontab中异常停止

PHP脚本在crontab中异常停止,php,mysql,cron,Php,Mysql,Cron,我设置了一个cron来运行这个脚本。我使用递归更新一个表(每次250行)。开始时运行良好,但几分钟后,它停止打印“Finish”。这似乎是服务器的内存问题。我检查了PhpMyadmin中的“进程”,确保它运行良好,但几分钟后就会停止。如何修复它 function update_mt_image_inventory($db, $from) { $current_img_id = htmlentities($_SERVER['argv'][1], ENT_QUOTES); if(

我设置了一个cron来运行这个脚本。我使用递归更新一个表(每次250行)。开始时运行良好,但几分钟后,它停止打印“Finish”。这似乎是服务器的内存问题。我检查了PhpMyadmin中的“进程”,确保它运行良好,但几分钟后就会停止。如何修复它

function update_mt_image_inventory($db, $from)
{
    $current_img_id = htmlentities($_SERVER['argv'][1], ENT_QUOTES);  
    if(!$current_img_id) $current_img_id = 999999999;   
    $interier = 250;
    $sql = "SELECT im.IMG_ID, im.IMG_FILENAME, im.SEAL_NUMBER , im.XXX FROM `mt_images` im WHERE im.IMG_ID < {$current_img_id} AND im.ACT_FLG = 1 ORDER BY im.IMG_ID DESC LIMIT {$from}, {$interier}";
    $re_check = @$db->sql_query($sql);
    if(@mysql_num_rows($re_check) > 0) {
        while($row = $db->sql_fetchrow($re_check)) {
            $img_id =  $row['IMG_ID'];
            $current_img_id = $img_id;:q!
            $inventory =  $row['XXX'];

            $sql = "SELECT USER_ID FROM tr_lines_alls WHERE IMG_ID = {$img_id} AND ACT_FLG = 1";
            $img_res = @$db->sql_query($sql);
            $img_count = @mysql_num_rows($img_res) ;
            if($img_count != $inventory && $img_id>0){
                $sql = "UPDATE mt_images SET XXX = {$img_count} WHERE IMG_ID = {$img_id}";
                @$db->sql_query($sql);
                $data = "{$img_id} | {$inventory} | {$img_count}";
                echo $data."\n";
                if($img_count>0) writeLog($data);
            }
            @mysql_free_result($img_res);
            unset($img_res);
        }
        @mysql_free_result($re_check);
        unset($re_check);
        echo "Checking next {$interier}/{$from} - Current: {$current_img_id} - Memory: ".memory_get_usage(false)."\n"; 
        if($from%5000 ==0){
            echo date("h:i:s")." --> 5000 records passed.\n";
        }
        update_mt_image_inventory($db, $from + $interier);
    } else {
        writeLog("mt_images finished");
    }
}
功能更新\u mt\u图像\u库存($db,$from)
{
$current\u img\u id=htmlentities($\u SERVER['argv'][1],ENT\u引号);
如果(!$current\u img\u id)$current\u img\u id=99999999;
$interier=250;
$sql=“从'mt_images`im中选择im.IMG_ID,im.IMG_FILENAME,im.SEAL_NUMBER,im.XXX,其中im.IMG_ID<{$current_IMG_ID}和im.ACT_FLG=1,按im.IMG_ID DESC LIMIT{$FROM},{$interier}”;
$re_check=@$db->sql_查询($sql);
if(@mysql\u num\u rows($re\u check)>0){
而($row=$db->sql\u fetchrow($re\u check)){
$img_id=$row['img_id'];
$current\u img\u id=$img\u id;:q!
$inventory=$row['XXX'];
$sql=“从所有的tr_行中选择用户_ID,其中IMG_ID={$IMG_ID}和ACT_FLG=1”;
$img_res=@$db->sql_查询($sql);
$img\u count=@mysql\u num\u行($img\u res);
如果($img\u count!=$inventory&&$img\u id>0){
$sql=“更新mt_图像集XXX={$img_count},其中img_ID={$img_ID}”;
@$db->sql\u查询($sql);
$data=“{$img_id}{$inventory}{$img_count}”;
回显$data。“\n”;
如果($img_count>0)写日志($data);
}
@mysql_免费_结果($img_res);
未结算($img_res);
}
@mysql\u free\u结果($re\u check);
未结算($重新检查);
echo“Checking next{$interier}/{$from}-Current:{$Current\u img\u id}-Memory:”.Memory\u get\u usage(false)。“\n”;
如果($from%5000==0){
回送日期(“h:i:s”)。“-->传递了5000条记录。\n”;
}
更新图片库存($db,$from+$interier);
}否则{
书面记录(“mt_图像完成”);
}
}

可能是时间限制设置。 在代码的第一行尝试以下操作:

set_time_limit(0);

首先,删除
@
所有地方。也许您可以将cron的输出保存在一个文件中,以查看是否存在Php错误,例如@sanmai的注释的
1*****Php myscript.Php>output.log
+1。
@
会抑制错误消息,因此您的脚本可能会悄无声息地崩溃。我确信这不是语法错误问题,因为当我在不使用cron的情况下运行它时。它运行良好,可以将文本打印到控制台。顺便问一下,如何为这个问题设置赏金?它不一定是语法错误,也可能是mysql错误。例如:如果插入出错(由于外键约束或类似的原因),您尝试在该查询的结果上添加受mysql\u影响的\u行,该怎么办。它将崩溃,但您不知道为什么.PHP Cli默认时间限制为0:我知道。。。但在他的服务器上,时间限制的值可能不是默认值。他说没有任何错误或其他原因,因此最合理的原因是时间限制。