Solved

Stopping a cronjob script from timing out

Posted on 2008-10-02
3
307 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

713 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