PHP Script Times Out During execution

Ive written a series of local scripts and they all execute with input -> process -> output all working correctly.  the script iterates through a list of objects and performs quite a few different queries on each object before moving onto the next.

it seems that when there are a large amount of objects the script seems to get down to the same point and then just freeze and timeout with an error saying query failed.

an example is:

Warning: mssql_query(): Query failed in /XXXX.php on line 201
Changed database context to 'XXX'.


the sql server is an 8 core zeon with 32gb ram and the system im running on is a 4core xeon with 4gb ram.  resource useage is very low, ive also tried the php ini settings by:

increasing the memory to 512MB
increasing the timeouts and code execution.

what can i do to solve this problem? any help would be gratly appretaited! :)
LVL 1
DarthNoodleAsked:
Who is Participating?
 
NerdsOfTechConnect With a Mentor Technology ScientistCommented:
I would continue to use usleep as the solution since it seems to be the ?only? solution.

Confused,
=NerdsOfTech
0
 
DarthNoodleAuthor Commented:
UPDATE:

The only way ive been able to mitigate this problem is by actually adding a usleep for 4 secs between the big sql statments!

this fixes the problem botch style but i would love a better solution instead of crippling my code to wait for 4 secs per 1/4 of an iteration.
0
 
NerdsOfTechTechnology ScientistCommented:
Read:
http://us3.php.net/set_time_limit

On the dangers of setting no time limit.

This should work for you:
set_time_limit (0);	// no script timeout limit.
ini_set('memory_limit','2048M'); // increase script usage limit to 2GB

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
DarthNoodleAuthor Commented:
Hi Nerds of Tech,

the list gets a little bit more furthur down but just seems to hang there with the same problem as before.

The  resource useage is:

top - 10:06:06 up 6 days, 18 min,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:  66 total,   1 running,  65 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3368828k total,   133804k used,  3235024k free,    59732k buffers
Swap:  2650684k total,        0k used,  2650684k free,    39516k cached

it doesnt say the query has failed at this time though...it just says ...

Changed database context to 'XXXX'.


0
 
DarthNoodleAuthor Commented:
my ini commands are:

        ini_set("mssql.connect_timeout",v5);
        ini_set("mssql.timeout", 60);

        set_time_limit (0);     // no script timeout limit.
        ini_set('memory_limit','2048M'); // increase script usage limit to 2GB
0
 
NerdsOfTechTechnology ScientistCommented:
Try this:
set_time_limit (0);     // no script timeout limit.
ini_set('max_input_time', (2*60*60)) // 2 hour input time
ini_set('max_execution_time', (12*60*60)) // 12 hour execution time
ini_set('memory_limit','2048M'); // increase script usage limit to 2GB

Open in new window

0
 
DarthNoodleAuthor Commented:
ive tried putting those in but im getting the same error :(

the script executes for:

real    1m2.205s
user    0m0.032s
sys     0m0.012s

and the second run is:

real    1m2.667s
user    0m0.016s
sys     0m0.012s
0
 
NerdsOfTechTechnology ScientistCommented:
http://us.php.net/manual/en/mssql.configuration.php

1 minute? Wow. Try this!
set_time_limit (0);     // no script timeout limit.
ini_set('max_execution_time', (12*60*60)) // 12 hour execution time
ini_set('memory_limit','2048M'); // increase script usage limit to 2GB
ini_set('max_input_time', (2*60*60)) // 2 hour input time
ini_set("mssql.timeout",(4*60*60)); // 4 hour connection timeout

Open in new window

0
 
NerdsOfTechTechnology ScientistCommented:
And finally try:
set_time_limit (0);     // no script timeout limit.
ini_set('max_execution_time', (12*60*60)) // 12 hour execution time
ini_set('memory_limit','2048M'); // increase script usage limit to 2GB
ini_set('max_input_time', (2*60*60)) // 2 hour input time
ini_set("mssql.timeout",(4*60*60)); // 4 hour connection overall timeout
ini_set("mssql.connect_timeout", 30*60); // 30 minute connection link timeout

Open in new window

0
 
DarthNoodleAuthor Commented:
at the moment its just sitting there, where it use to timeout/error before.

im executing a series of stored proc's, i dont think that will have a big diff will it since most of the legwork would be done by the sql server and the free memory and load on that is negligable.
0
 
NerdsOfTechTechnology ScientistCommented:
Eureka I am glad you said PROCS!
0
 
NerdsOfTechTechnology ScientistCommented:
Now I know why usleep fixed your problem!
"mssql.max_procs" defauls as -1 = which is actually a limit of 25 PROCS
set_time_limit (0);     // no script timeout limit.
ini_set('max_execution_time', (12*60*60)) // 12 hour execution time
ini_set('memory_limit','2048M'); // increase script usage limit to 2GB
ini_set('max_input_time', (2*60*60)) // 2 hour input time
ini_set("mssql.timeout",(4*60*60)); // 4 hour connection overall timeout
ini_set("mssql.connect_timeout", 30*60); // 30 minute connection link timeout
ini_set("mssql.max_procs", 128); // -1 = 25 procs // 128=128 procs

Open in new window

0
 
DarthNoodleAuthor Commented:
it still freezes, my commands look like this..

        set_time_limit (0);     // no script timeout limit.
        ini_set('max_input_time', (30*60)); // 30min input time
        ini_set('max_execution_time', (60*60)); // 1hr execution time
        ini_set('memory_limit','2048M'); // increase script usage limit to 2GB
        ini_set('mssql.timeout',(10*60)); // 10 min connection timeout
        ini_set('mssql.connect_timeout', 10*60); // 10 minute connection link timeout
        ini_set('mssql.max_procs', 256); // -1 = 25 procs // 128=128 procs

do you have any other ideas? ive tried to keep it all php as my system is coded entirely in php, however im starting to think that i may have to recode the processing stuff in java or something.
0
 
NerdsOfTechTechnology ScientistCommented:
what did it used to do when you used usleep()
0
 
DarthNoodleAuthor Commented:
it just paused for the duration of usleep and then afterwards it continued executing, generally ive increased the usleep value and it gets to a point where it will continue executing.

an example of this was parsing xml, the script parsed xml but for big amount of data i had to have usleep in a few areas...when i set a usleep of 1sec it still died but when i set it to sleep for 3 secs the script worked.
0
 
DarthNoodleAuthor Commented:
yeah,

its worked on previous scripts but with this script it seems to not want to work regardless of how long i leave it.

im going to have to fall back and port this partiqular script to a better language that can handle it.

thanks alot for your help though! you were that helpfull ill close the topic and award the points to you with an A grade!
0
 
DarthNoodleAuthor Commented:
I belive we exausted almost all avenues of approach with this and i was very impressed with your effort to help me so im going to award you the points regardless of me porting the script to another language.
0
 
NerdsOfTechTechnology ScientistCommented:
Thanks! Best of luck with your new script.

Sincerely,
=NerdsOfTech
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.