views:

45

answers:

2

Hello,

I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100 loops with sleep(15)]

The execution time for the statements inside loop is very less.

My scripts are hosted on GoDaddy. I am sure that they are having some kind of limit on execution time.

My question is, are they concerned with "the total CPU execution time" or the total running time.

+3  A: 

They will be concerned with the CPU Execution Time, not the total running time unless connections are an issue and you're using a lot of them (which it doesn't sound like you are).

Running time, as in a stopwatch, doesn't matter much to a shared host, if your loop runs for 3 years but only uses 0.01% CPU doing it, it doesn't impact their ability to host. However if you ran for 3 years at 100% CPU, that directly impacts how many other applications/VMs/whatever can be run on that same hardware. This would mean more servers to host the same number of people which means money...that they care about.

For the question in the title: they are very different. With sleep() and the same amount of total time, that means the actual work the CPU is doing is much less because it can do the work, sleep/idle, and still finish in the same amount of time. When you're calling sleep() you're not taxing the CPU, it's a very low-power operation for it to keep the timer going until calling your code again.

Nick Craver
A: 

This is the typical time limit:

http://es2.php.net/manual/en/info.configuration.php#ini.max-execution-time

It can normally be altered in a per-script basis with ini_set(), e.g.:

ini_set('max_execution_time', 20*60); // 20 minutes (in seconds)

Whatever, the exact time limits probably depend on how PHP is running (Apache module, fastCGI, CLI...).

Álvaro G. Vicario
I've always preferred the `set_time_limit()` function, personally. I don't know if it's completely equivalent to calling ini_set(). I suppose I've always just assumed that if they created a function for it, it's probably good to use it.
Frank Farmer