?
Solved

PHP Script Times Out During execution

Posted on 2009-05-20
18
Medium Priority
?
418 Views
Last Modified: 2013-12-12
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! :)
0
Comment
Question by:DarthNoodle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24430237
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24436582
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
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24471322
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 1

Author Comment

by:DarthNoodle
ID: 24471330
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24471349
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
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24471427
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24471517
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24471526
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
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24471885
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24477261
Eureka I am glad you said PROCS!
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24477314
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
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24481293
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24481310
what did it used to do when you used usleep()
0
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24481340
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
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 2000 total points
ID: 24481470
I would continue to use usleep as the solution since it seems to be the ?only? solution.

Confused,
=NerdsOfTech
0
 
LVL 1

Author Comment

by:DarthNoodle
ID: 24481655
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
 
LVL 1

Author Closing Comment

by:DarthNoodle
ID: 31583414
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
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24486602
Thanks! Best of luck with your new script.

Sincerely,
=NerdsOfTech
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

801 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