我有一个运行很长时间的脚本,比如 10-15 小时。 该脚本在整个过程中执行良好,但脚本中有一个 mysql 表创建查询,其中 PHP 抛出警告“PHP 警告:发送 QUERY 数据包时出错...”。并且脚本终止。还实现了异常处理,但脚本在捕获任何异常之前终止。
重要的是要注意,如果循环在短时间内完成,脚本运行良好并成功执行所有内容。
这是代码演示:
<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);
ini_set('max_input_vars', 10000);
try{
//***** ****/
//loop running and doing some long resource intensive operation involving php and mysql
//***** ****/
$tableCreationQuery = "CREATE TABLE `some_table` (
id INT NOT NULL AUTO_INCREMENT,
some_id INT NULL DEFAULT NULL,
some_text TEXT DEFAULT NULL,
PRIMARY KEY (id),
INDEX (some_id),
) ENGINE = InnoDB DEFAULT CHARSET = utf8";
//script executes till here properly
//PHP notice is thrown on the below line and the script execution terminates
$tableCreationQueryResult = mysqli_query($db, $tableCreationQuery);
if (!$tableCreationQueryResult) {
throw new Exception("Connections table creation query failed: " . $db->error);
}
}catch (Exception $e){
$status = "error";
$message = $e->getMessage();
}
?>
只需从最后一行删除“,”即可
$tableCreationQuery = "CREATE TABLE `some_table` (
id INT NOT NULL AUTO_INCREMENT,
some_id INT NULL DEFAULT NULL,
some_text TEXT DEFAULT NULL,
PRIMARY KEY (id),
INDEX (some_id), <---Here
) ENGINE = InnoDB DEFAULT CHARSET = utf8";