我已经设置了一个crontab来每分钟运行一次测试。一切都很好,直到我在php文件中放入一些mysql查询。
工作srontab:
* * * * * /usr/bin/php /path/to/script/cront.php
Php文件内容:
mail('email@gmail.com', 'Testing cron','Testing cron job');
然后它停止执行。我正在使用Putty登录以登录SSH。我四处搜索,这可能是一个许可问题,我不知道如何检查我的许可。
代码停止了cron:
$sql = "SELECT * FROM bookings";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {mail($row['email'], 'Testing cron','Testing cron job');}
有人可以帮忙吗?
答案 0 :(得分:0)
添加此项以查看是否存在可能导致执行中断的SQL错误。
$con = new mysqli('host', 'user', 'pw');
if ($con->connect_errno > 0)
die('Unable to connect to database [' . $con->connect_error . ']');
if (!$result = $con->query($query)) // of course, it's more usefull with a complex query :-)
die('There was an error running the query [' . $con->error . ']');
while($row = $result->fetch_assoc()) {/* ... */}
按如下方式将日志添加到您的cron
* * * * * /usr/bin/php /path/to/script/cront.php >> /var/log/myjob.log 2>&1