简体   繁体   English

Cron 不会在 Centos7 中的 PHP 脚本中执行 MySql

[英]Cron won't execute MySql in PHP Script in Centos7

Hello and thanks for looking at this.您好,感谢您查看此内容。

Cron Jobs didn't execute this morning because they send emails and I didn't get them. Cron Jobs 今天早上没有执行,因为他们发送电子邮件而我没有收到。 Running Centos 7 at GoDaddy.在 GoDaddy 运行 Centos 7。

Here's the cron command...这是cron命令...

/usr/local/bin/ea-php56 /home/rbigroup/public_html/cron/cron-test.php >/dev/null 2>&1 /usr/local/bin/ea-php56 /home/rbigroup/public_html/cron/cron-test.php >/dev/null 2>&1

When testing the script in the browser, works fine.在浏览器中测试脚本时,工作正常。 However when I remove the MySql in the script, the Cron works fine.但是,当我删除脚本中的 MySql 时,Cron 工作正常。

I'm totally baffled an flustered.我完全感到困惑和慌乱。 Any help is super appreciated!任何帮助都非常感谢! Thanks for your time!谢谢你的时间!

Here's the php code...这是 php 代码...

<?php require $_SERVER['DOCUMENT_ROOT']."/Connections/connect.php";  ?><?php include "cron-recipients.php"; ?>
<?php



echo $_SERVER['DOCUMENT_ROOT'];
$date = date('Y-m-d',$date_start);

echo $date."<br>";

mysqli_select_db($db);
$insertSQL = sprintf("INSERT INTO test_table (text_field,`date_field`) VALUES ('Hello','$date')");

echo $insertSQL."<br>";
$Result1 = mysqli_query($db,$insertSQL) or die(mysqli_error($db)); 




$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: noreply@rbirestaurantgroup.com' . "\r\n";

$subject = "Confirming Cron-Test Is Working on PPie Server";

$to = $RECIPIENT_SET1; //attach emails to the TO field 
//$to = 'apsubmit@secureserver.net'; 

$message = '<html>
    <head>
      <title>Cron Report</title>
    </head>
    <body><h2>Cron Test</h2>
    Your test works.
    </body>
    </html>';

mail($to, $subject, $message, $headers);

echo "Cron Tester Complete"."<br>";       

echo $to;

 ?>

Problem solved!问题解决了!

Hopefully this will help people in the future.希望这对未来的人们有所帮助。 It turns out that the problem was this line at the very top of my script.事实证明,问题出在我脚本顶部的这一行。

<?php date_default_timezone_set('America/New_York'); ?>

I added it because I noticed that the time when the Crons at GoDaddy fire is there 3 hours earlier than my time here on the east coast.我添加它是因为我注意到 GoDaddy 火灾的 Cron 时间比我在东海岸的时间早 3 小时。 Its 3am at the server when its 6 am here.当它早上 6 点在这里时,它是凌晨 3 点在服务器上。 I wanted to sync the times it was going out of the server so I added the above code at the top and uploaded.我想同步它离开服务器的时间,所以我在顶部添加了上面的代码并上传了。

I tested the script in the browser, made the cron command, just like all the other ones, and set the time for the morning.我在浏览器中测试了脚本,像所有其他命令一样发出了 cron 命令,并设置了早上的时间。 Called it a day.收工了。 Morning came.早晨来了。 No email responses from any cron and no SQL Inserts.没有来自任何 cron 的 email 响应,也没有 SQL 插入。

I then tried to test the script with cron by setting a cron command to hit every 1 minutes but it wasn't working.然后,我尝试通过将 cron 命令设置为每 1 分钟命中一次来使用 cron 测试脚本,但它不起作用。 No email response or SQL insert.没有 email 响应或 SQL 插入。 Tried everything.什么都试过了。 Different cron commands and what not.不同的 cron 命令等等。 Hit up Stack Overflow (total newbie here;)) Sweatin...点击 Stack Overflow(这里是新手;))汗水......

After a few hours on the phone with GoDaddy and going thru every action, the representative realized when I mentioned the above code that it may have done some thing to the php.ini file.在与 GoDaddy 通了几个小时的电话并完成了所有操作后,当我提到上面的代码时,代表意识到它可能对 php.ini 文件做了一些事情。 Sure enough it had altered it somehow, causing the cron to not fire when SQL was in the script for some odd reason.果然它以某种方式改变了它,导致当 SQL 出于某种奇怪的原因出现在脚本中时,cron 无法触发。 He said it added some weird characters in the file causing the server to fall back to just the server INI file.他说它在文件中添加了一些奇怪的字符,导致服务器回退到服务器 INI 文件。 He corrected the file and boom... all back to normal.他更正了文件,然后砰……一切都恢复了正常。

Anyway this had me stumped.无论如何,这让我很难过。 But all is well and learned a lesson.但一切都很好,吸取了教训。 Don't mess with the cron.不要乱用cron。 Thanks for everyones help.感谢大家的帮助。 Hope this helps others!希望这对其他人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM