对于在某些情况下未执行的查询,我遇到了一个奇怪的问题。我很确定他们查询自己不是问题,因为我在它之前插入了一个非常简单的查询,这不会是错误的,但也不会执行。
以下是对此脚本执行操作的简短说明:脚本每分钟都由cronjob执行。它会检查上传的PDF文件列表,并将它们拆分为单独的文件(如果尚未拆分),然后生成JPG预览文件。
对于普通的PDF文件,它完全正常。但是,上传大型PDF文件(例如30MB,28页)会使脚本在某些时候无缘无故停止(请参阅内联注释)。我错误地记录了PDF分割过程($ pdf->进程),它完全正常。
一位朋友怀疑这个奇怪的错误可能是由于服务器上的memoryspace不足或达到数据库连接的最大数量所致,但我们都没有太多关于这类事情的线索。也许你们其中一个人?
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脚本的执行。
答案 0 :(得分:0)
也许你正在点击PHP“最长脚本执行时间”?我相信它默认设置为30秒。尝试增加脚本开头的最长执行时间:
ini_set('max_execution_time',2*60); // will set it to 2 minutes
HTH