PHP没有';长时间处理后无法执行查询


PHP doesn't execute query after long processing

我遇到了一个奇怪的问题,在某些情况下没有执行查询。我很确定他们的查询本身没有问题,因为我在它之前插入了一个非常简单的查询,这不会错,但也不会被执行。

下面简要解释一下这个脚本的作用:cronjob每分钟都在执行这个脚本。它检查上传的PDF文件列表,并将它们拆分为单独的文件(如果尚未拆分),然后生成JPG预览。

它适用于普通的PDF文件。然而,上传一个大的PDF文件(例如,30MB,28页)会使脚本在某个时候无故停止(请参阅内联评论)。我已经错误地标记了PDF分割过程($PDF->过程),它运行得非常好。

一位朋友怀疑,这个奇怪的错误可能是由服务器上的内存空间不足或数据库连接达到最大值引起的,但我们都对这类事情一无所知。也许你们中的一个有?

ignore_user_abort(0);
set_time_limit(0);
error_reporting(-1);
if($_SERVER['SERVER_ADDR'] == '127.0.0.1')
    include_once("../config.php");
else
    include_once("/home/httpd/docs/myproject/inc/config.php");
include_once(ROOT."inc/db.class.php");
include_once(ROOT."inc/functions.php");
include_once(ROOT."inc/generate_previews.class.php");
$db = DB::getInstance();
$select_file_name_query = "SELECT * FROM z_tmp_preview_files WHERE id > '0' AND status = '0' AND file_name != ''";
$result = $db->query($select_file_name_query);

while($job_preview = $db->fetchNextObject($result)){
    $job_id = $job_preview->rel_job_id;
    $file = $job_preview->file_name;
    $set_inprocess_file_name_query = "UPDATE z_tmp_preview_files SET status = '1' WHERE id = '".$job_preview->id."'";
    $set_inprocess_file_name_result = $db->execute($set_inprocess_file_name_query);
    $file_info = explode('.',$file );
    $file_name = $file_info[0];
    $jpg_file = str_replace(".pdf", ".jpg", $file);
    // =======================================================================================
    // PDF-file is split into separate pages and JPG-previews are generated with the McPdf Class
    // This works just fine, even with very large files, but may take some minutes.
    // =======================================================================================
    $pdf = new McPdf($job_id);
    $pdf->process();
    $files_burst = LoadFiles("".ROOT."intern/jobs/".$job_id."/burst/");
    $page_count = sizeof($files_burst);
    error_log("'nTEST:",3,ERROR_DIR);
    $sql = "SELECT annotation_type FROM annotations";
    $value = $db->queryUniqueValue($sql);
    // =======================================================================================
    // This is where the PHP-script just stops. Non of the following error_logs are shown,
    // nor will the UPDATE-query be executed. The previous SELECT-query probably hasn't been executed as well.
    // =======================================================================================
    error_log($value,3,ERROR_DIR);
    $remove_file_name_query = "UPDATE z_tmp_preview_files SET status = '2' WHERE id = '".$job_preview->id."'";
    error_log("'n'ncheck query:",3,ERROR_DIR);
    error_log(" ".$remove_file_name_query,3,ERROR_DIR);
    $remove_file_name = $db->execute($remove_file_name_query);
    error_log("'npossible error:".$remove_file_name."'n",3,ERROR_DIR);
}

db.class工作得很好,我在项目中到处都用它,但如果你想知道queryUniqueValue的作用,下面是代码:

function queryUniqueValue($query, $debug = -1){
    $query = "$query LIMIT 1";
    $this->nbQueries++;
    $result = mysql_query($query) or $this->debugAndDie($query);
    $line = mysql_fetch_row($result);
    $this->debug($debug, $query, $result);
    return $line[0];
}

编辑:这里有另一个猜测:也许这是某种mysql超时?只有当McPdf类需要很长时间来处理时,问题才会出现。据我所知,在执行$pdf-process()之后,第一个mysql查询将中止PHP脚本的执行。

也许您达到了PHPs"最大脚本执行时间"?我认为它默认设置为30秒。尝试在脚本开始时增加最长执行时间:

ini_set('max_execution_time',2*60); // will set it to 2 minutes

HTH