简体   繁体   中英

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. Running Centos 7 at GoDaddy.

Here's the cron command...

/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.

I'm totally baffled an flustered. Any help is super appreciated! Thanks for your time!

Here's the php code...

<?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. Its 3am at the server when its 6 am here. 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. Called it a day. Morning came. No email responses from any cron and no SQL Inserts.

I then tried to test the script with cron by setting a cron command to hit every 1 minutes but it wasn't working. No email response or SQL insert. Tried everything. Different cron commands and what not. Hit up Stack Overflow (total newbie here;)) Sweatin...

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. Sure enough it had altered it somehow, causing the cron to not fire when SQL was in the script for some odd reason. He said it added some weird characters in the file causing the server to fall back to just the server INI file. 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. Thanks for everyones help. Hope this helps others!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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