Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a CRON job calling a PHP script using wget; I've set it up like that as I have all the objects set up and can be used elsewhere in the site.

Calling this PHP script by typing in the address the script runs with no problems; it's not a particularly long running process, around 6 seconds (max). However running with the CRON job, one of the MySQL processes runs upto 100% CPU and kills the responsiveness on the rest of the server. The exception that I receive is a mixture between 'too many connections', 'query execution was interrupted' and 'can't connect to local server through socket..'. I suspect all symptomatic of the 100% CPU usage. I can't kill the process, I have to (soft) restart the server.

The CRON call is the following:

*/10 * * * * /usr/bin/wget --user-agent="MyWebsite.com" --quiet --tries=0 -O - http://www.example.com/cron/script?password=example

Could this be DOSing my server?

TIA

  • Update: Just to say that the script sometimes runs for a little while (max 24 hours) and sometimes as little as a few minutes.
share|improve this question
1  
Did you try to redirect the error to a log file to see what happens. Can you run it with php binary /usr/bin/php /path/to/php/cron > /tmp/cron.log 2>&1? –  quanta Sep 16 '11 at 2:18
    
Thanks quanta, I would vote up your comment but I don't have enough rep! –  Ian Sep 17 '11 at 21:14

3 Answers 3

Moving on from Quanta's comment, I bit the bullet and implemented my framework as a CLI call instead of HTTP. Easier than expected as I only had to change my 'httpvariables' class to accept command line arguments as well as HTTP. Now, no MySQL problems! There must be something hanging onto the MySQL session when using WGET. I read a lot of places and there wasn't any information to suggest that this should be an issue, and some places suggested that WGET was actually a quicker way to call a PHP script from a CRON schedule.

I solved the initial problem with wget by also setting -tries=1 rather than 0, as I assume that the server response was too slow so wget was querying it again, and again, effectively DOSing my server, with my server. This allowed the server to recover itself, but it wasn't acceptable to have that slowing things down for any page requests.

Thanks for the replies, made me think about a few alternatives!

share|improve this answer

Is http://www.example.com your server??

I mean hard to understand how wget related to mysql...

May be you ask you script by wget on the same server? and this script kill CPU. Just an idea.

share|improve this answer
    
I just got what you meant. Yes, that's what was killing the server, but I wasn't sure why the request was ok in a regular call and yet messed up my server in the CRON. The MySQL stuff was called by the PHP script. –  Ian Sep 17 '11 at 21:00
    
So, you can open the php script , and show you sql queries which kills mysql, right? –  Korjavin Ivan Sep 18 '11 at 6:07

You have to tell Cron which user to run the command as. The cron job format is:

# m h dom mon dow user  command

Alternatively, you could create your own crontab by crontab -e. This will have the ready skeleton for you to edit. Another thing to try is to make sure Cron likes the command syntax.

share|improve this answer
    
It looks to me like it's running from a user crontab already. –  Iain Sep 16 '11 at 7:28
    
It's in a cron script already which is why I've got the cron syntax in the question. –  Ian Sep 17 '11 at 21:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.