Solved

Stopping a cronjob script from timing out

Posted on 2008-10-02
3
305 Views
Last Modified: 2013-12-12
I'm running a PHP script on my SHARED server (hostgator.com) and I want to run it as a cronjob, but I can't because the script is not working correctly.

The script is meant to load info from eBay through the eBay API.

When I try to test the script in FF, I get a blank webpage after ~2 mins (the script is supposed to write a success message at the end).
In IE, I get the error that the page cannot be displayed (after ~2 mins).

I have taken a look at my mySQL DB, and I noticed that the script WORKS, but stops halfway through (only half the info is loaded).

What could be wrong with it?
Is it timing out, and if so, why doesn't FF say that it's timed out.

To check the phpinfo() settings, you can go to http://www.esentials.net/scriptTests/phpinfo.php

Any ideas?

0
Comment
Question by:sjamal_hsj
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
ID: 22629549
To remove the time limit on php use

set_time_limit(0);

However, the 2 minutes sounds like a server timeout issue rather than a php timeout issue. The Server will impose it's on limits on scripts accessed by a browser. For instance, the server I run on my local machine is set to timeout in 5 minutes, so even if I set the timeout in php to longer the server will stop.

I cannot say why FireFox does not display an error.
0
 

Author Comment

by:sjamal_hsj
ID: 22629688
I was using set_time_limit(600), but I tried set_time_limit(0) and it seems to work fine now

I plan to run this script as a cronjob, so I'd like to know (just in case):

1. Do server timeout issues affect cronjobs? Or only requests from a browser?

2. Is there any way of having a cronjob redirect (sort of like the header function) to continue running the script?

thnx
0
 
LVL 18

Assisted Solution

by:Hube02
Hube02 earned 500 total points
ID: 22629818
1) Server timeouts should not affect cronjobs, at least not in my experience.

2) I do not believe there is a way to redirect in a cronjob, but, since there are no timeout issues if you use set_time_limit(0) then there is really no reason to

 I used to work at a place that did quite a bit with crons. One in particular I remember was set to run on sunday night at 3 am because it took more than 30 minutes to complete. No I didn't write it, but I inherited it. It would send me an email every week to tell me when it started, when it stopped and usually a list of a couple thousand entries of files that were altered or errors it encountered.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now