Solved

Stopping a cronjob script from timing out

Posted on 2008-10-02
3
304 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP and Soap 3 26
MYSQL simple update statement 3 32
Time difference 10 32
confirm popup before record delete takes place 87 20
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

6 Experts available now in Live!

Get 1:1 Help Now