Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by David Atkin
at 2024-08-09 02:49:17
Point:400 Replies:12 POST_ID:828722USER_ID:11621
Topic:
PHP Scripting Language;Apache Web Server;Linux Programming
Hello experts,
I am having a problem on one of my CentOS Servers.
I have a php script that checks a mysql database, if a value = 1 then it sends an sms and email to the relevant person with some data. When running the script manually via a web browser or on the server by command it does exactly as it should, it sends the email, sends the sms and updates my DB correctly (changing a value to 0).
However when I try and run the same script from a crontab -e (logged in as root) it will loop my script. I am getting multiple emails and sms.
My Cron Job:
MAILTO="me@myemail.com"
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
The mailto just sends me an email confirming that it has run the Cron. I get multiple of these aswell.
I've tried running the cron as a wget and putting the url in but it does the same thing.
I've also tried running the script from the system crontab file and under different users.
I'm happy that my php script is fine as it runs manually perfectly.
Any suggestions?
I am having a problem on one of my CentOS Servers.
I have a php script that checks a mysql database, if a value = 1 then it sends an sms and email to the relevant person with some data. When running the script manually via a web browser or on the server by command it does exactly as it should, it sends the email, sends the sms and updates my DB correctly (changing a value to 0).
However when I try and run the same script from a crontab -e (logged in as root) it will loop my script. I am getting multiple emails and sms.
My Cron Job:
MAILTO="me@myemail.com"
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
The mailto just sends me an email confirming that it has run the Cron. I get multiple of these aswell.
I've tried running the cron as a wget and putting the url in but it does the same thing.
I've also tried running the script from the system crontab file and under different users.
I'm happy that my php script is fine as it runs manually perfectly.
Any suggestions?
Author: David Atkin replied at 2024-08-15 02:15:35
Found the fix my self but have awarded assist points for the experts time and input.
Thanks again
Thanks again
Expert: Ray Paseur replied at 2024-08-10 10:05:22
Glad you got it pointed in the right direction! Best regards, ~Ray
Accepted Solution
Author: David Atkin replied at 2024-08-10 08:43:16
Hello,
I've found the problem. The server was running multiple Cron Processes for some reason. The Cron Job was being run successfully but it was being run by all the open processes.
I restarted the Server and it worked fine using the existing script and cron job.
One of the other admins was adding some cron jobs under another user account which may have caused the problem. I am currently monitoring this.
Thank you for your assistance. I will award assist points
I've found the problem. The server was running multiple Cron Processes for some reason. The Cron Job was being run successfully but it was being run by all the open processes.
I restarted the Server and it worked fine using the existing script and cron job.
One of the other admins was adding some cron jobs under another user account which may have caused the problem. I am currently monitoring this.
Thank you for your assistance. I will award assist points
Assisted Solution
Expert: Ray Paseur replied at 2024-08-09 09:52:08
100 points EXCELLENT
I think we could discern the issue, but probably only if we have the code and can add some "checkpoints" to visualize the logic and data.
Author: David Atkin replied at 2024-08-09 05:27:57
Hi Ray,
Sorry, I forgot to mention, when I stated that I ran the script manually, I meant by via both command line and the web. The script runs perfectly via command line - I get the exact amount of SMS messages that I've specified, and also the exact amount of emails, all of which are successfully updated in the database. No errors are reported to the console with error reporting turned on either, only my echoes from debugging, so I feel that there are no syntax errors. Would there be any reason why the script runs fine when manually ran from the command line as both root and another user, yet behaves differently when using CRON?
I've gone over the code multiple times and it just seems that it's looping within an if block, but only when using CRON. Can you offer any more advice please?
Sorry, I forgot to mention, when I stated that I ran the script manually, I meant by via both command line and the web. The script runs perfectly via command line - I get the exact amount of SMS messages that I've specified, and also the exact amount of emails, all of which are successfully updated in the database. No errors are reported to the console with error reporting turned on either, only my echoes from debugging, so I feel that there are no syntax errors. Would there be any reason why the script runs fine when manually ran from the command line as both root and another user, yet behaves differently when using CRON?
I've gone over the code multiple times and it just seems that it's looping within an if block, but only when using CRON. Can you offer any more advice please?
Author: David Atkin replied at 2024-08-09 03:51:47
Hi Ray,
Thank you for your input, we will give this a try.
Thank you for your input, we will give this a try.
Assisted Solution
Expert: Ray Paseur replied at 2024-08-09 03:33:54
200 points EXCELLENT
script is fine as it runs manually
That might or might not be true. When you run a script "manually" via a web browser, it's running in a web environment. The paths and permissions may be different in the CRON environment. If the script is not adequately testing for errors, it may be encountering things like failed SQL queries, but it may be ignoring these failures.Typical data base engines are not black boxes -- they can and will fail for reasons that may be outside of your control, so it is important to test for the success or failure of the queries, and to visualize the error messages when a query fails. This article, while it's mostly about upgrading MySQL, shows how to detect and visualize query failures in each of the popular extensions.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Since your CRON job does not have any browser output, here is a technique you can use to get debugging information out of the CRON script. At the logical top of the script, add these lines to cause the output buffers to collect messages:
At the logical end of the script, add these lines to send the messages to you.
Of course you will want to put your own email address into the mail command. You will get an email every time CRON runs, so you may not want to leave this in place long term.
You can run phpinfo() in both the CRON and web environment and compare the output. Does your script depend on any variables that are different between the two environments?
And finally, if you wan to post the code here, we can verify your error checking and ensure that any errors will get spit into the output buffers, and subsequently emailed to you.
You can run phpinfo() in both the CRON and web environment and compare the output. Does your script depend on any variables that are different between the two environments?
And finally, if you wan to post the code here, we can verify your error checking and ensure that any errors will get spit into the output buffers, and subsequently emailed to you.
Author: David Atkin replied at 2024-08-09 03:29:31
Hello,
Yes there is no difference in the file.
"MAILTO="me@myemail.com"
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php"
I will comment out the email php and let you know if it makes any change
Yes there is no difference in the file.
"MAILTO="me@myemail.com"
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php"
I will comment out the email php and let you know if it makes any change
Expert: duncanb7 replied at 2024-08-09 03:24:16
You mean
there is only one line ,
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
in your cron-job file, Right ? and the line is same as above and no different , right ?
Please disable the email function for user in php script
and do the cron-job again to see whether it won't send you mutilple email, first ?
there is only one line ,
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
in your cron-job file, Right ? and the line is same as above and no different , right ?
Please disable the email function for user in php script
and do the cron-job again to see whether it won't send you mutilple email, first ?
Author: David Atkin replied at 2024-08-09 03:12:10
Hello, thank you for the quick reply
Yes it emailed me about 10 times I think.
I've gone to /var/spool/cron and it just shows the users and their cron jobs. The only one active is the one under root. Its the same as I posted above.
Yes it emailed me about 10 times I think.
I've gone to /var/spool/cron and it just shows the users and their cron jobs. The only one active is the one under root. Its the same as I posted above.
Assisted Solution
Expert: duncanb7 replied at 2024-08-09 03:07:22
100 points EXCELLENT
There is your system cron-job file located at /var/spool/cron/yousitename
Please log into root access and review the item
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
in the file, yoursitename, to see what is wrong with that
Please log into root access and review the item
53 20 * * * /usr/bin/php /var/www/html/website/system/crons/upcoming.php
in the file, yoursitename, to see what is wrong with that
Expert: duncanb7 replied at 2024-08-09 03:04:09
The mailto just sends me an email confirming that it has run the Cron. I get multiple of these aswell.
How often the multiple email to you ? 10 per hour ?