Solved

PHP Script Times Out During execution

Posted on 2009-05-20
18
408 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
  • 9
  • 9
18 Comments
 
LVL 1

Author Comment

by:DarthNoodle
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:DarthNoodle
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Eureka I am glad you said PROCS!
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
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
Comment Utility
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
Comment Utility
what did it used to do when you used usleep()
0
 
LVL 1

Author Comment

by:DarthNoodle
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks! Best of luck with your new script.

Sincerely,
=NerdsOfTech
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …

762 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