-1

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;

 ?>
jbobfunky
  • 1
  • 3
  • 1
    As we can't see what your script does, not sure how we can help. Also if you say removing MySql in the script works, there is probably an error log somewhere telling you what went wrong. – Nigel Ren May 31 '20 at 13:47
  • No idea, please show the code. Also not getting an email doesnt show a CRON worked/didn't. Write the events that fire to a log file with `>>`. – user3783243 May 31 '20 at 13:47
  • Thanks for responding! And sorry, I'm new to allot of this. Here is the php code – jbobfunky May 31 '20 at 14:09
  • Code posted in thread.. – jbobfunky May 31 '20 at 14:12
  • Answer to your question is here: [link](https://stackoverflow.com/questions/2100545/serverdocument-root-does-not-work-in-the-php-script-running-through-cron) $_SERVER['DOCUMENT_ROOT'] is not set, because it is not run by web server, but cron – Robert May 31 '20 at 15:07
  • I changed the connection script with an absolute link and still fails to run the script when any SQL calls are in it. As soon as I comment out any call mysql, the cron works flawlessly and I get my test email! I just don't get it. Above is a test script to just test cron runs and inserts data to my tables and sends an email. It was working fine with the cron command...wget -q /dev/null 2>&1 https://www.positivepie.com/cron/cron-test.php until now. Now that doesn't work at all... – jbobfunky May 31 '20 at 15:34
  • Now I'm using... /usr/local/bin/ea-php56 /home/rbigroup/public_html/cron/cron-test.php >/dev/null 2>&1 and again the script only works when I comment out the sql. It's killing me, not to mention critical the crons work ofcourse. – jbobfunky May 31 '20 at 15:36
  • I would check `mysqli_select_db($db);` it should be link to connection and database name as per docs: mysqli_select_db ( mysqli $link , string $db) then your query should be: mysqli_query($link, $insertSQL); – Robert May 31 '20 at 15:55

1 Answers1

0

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!

jbobfunky
  • 1
  • 3