调试cron PHP脚本 [英] Debugging cron PHP script
问题描述
<?php
ini_set("display_errors",1);
error_reporting(-1);
set_include_path('root/push');
require_once('../../var/www/includes/database.php');
require_once('pushAPNS.php');
date_default_timezone_set('Europe/London');
$departure = (string)date('H:i');
$timeNow = "$departure:00";
class Journey {}
try {
// Get all UDIDs that need to be sent a notificaiton now
$stmt = $conn->prepare("SELECT udid, bus.registration, vjc.vehicle_journey_reference, bus.line, `to`.operator_short_name AS operator, traveline.getDestinationFromJourney(vjc.vehicle_journey_reference) AS destination
FROM push_request
JOIN cron ON cron.time = :timeNow
JOIN traveline.vehicle_journey_code vjc ON vjc.vehicle_journey_reference = cron.vehicle_journey_reference
JOIN bus ON bus.journey = vjc.code
JOIN traveline.operator `to` ON `to`.operator_code = bus.operator_code
WHERE push_request.vehicle_journey_reference = vjc.vehicle_journey_reference");
$stmt->execute(array(':timeNow' => $timeNow));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
echo $e->getMessage();
}
// Notify every UDID their journey is now trackable
foreach ($results as $result) {
$journey = new Journey();
$journey->operator = $result['operator'];
$journey->line = $result['line'];
$journey->departure = $departure;
$journey->destination = $result['destination'];
pushAPNS($result['udid'], $journey);
}
// Debugging
$conn->query("INSERT INTO a (`time`) VALUES ('$timeNow')");
?>
上述代码是由cron在服务器上每分钟执行的。代码在每次查询返回结果时都到达最后一行。我在脚本执行时似乎没有看到PHP错误日志中的任何错误,任何想法如何调试这可以解决我的问题?
The above code is executed every minute on the server by cron. The code reaches the last line every time apart from when the query returns a result. I can't seem to see any errors in the PHP error log when the script executes, any ideas how I can debug this to fix my problem?
我应该添加如果我手动执行的脚本结果将返回脚本工作正常。只是cronjob不喜欢查询结果
I should add that if I execute the script manually when results will be returned the script works fine. It's just the cronjob that is not liking the query results
Crontab:* * * * * / usr / bin / php /root/push/sendPushNotifications.php
Crontab: * * * * * /usr/bin/php /root/push/sendPushNotifications.php
推荐答案
尝试此
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
它也将启动其他错误...但仍然 - 找到您的命令行日志。对我来说,它在 /etc/php5/cli/php.ini
,然后搜索错误报告,并将所有开
设置 error_log = ./debugged_php_errors.log
或类似的东西。
不是每个错误都会在它运行的地方创建日志文件。
it will also start the other errors... But still - find your command line logs. For me it was in /etc/php5/cli/php.ini
then search for error reporting and turn all to On
set your error_log = ./debugged_php_errors.log
or something similar.
Not each error will create the log file in the place its running.
这篇关于调试cron PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!