Log in

View Full Version : Timeouts



cooper30115
09-30-2010, 12:39 AM
Hello. I wrote a PHP script that contains a SOAP request. I used this script before and it worked perfectly. The last time I tried to use it, the query contained a large amount of data - a much larger amount of data than I had retrieved in earlier uses of the script. Every time I ran the latest script I would get either a "max_execution_time" or "500 Internal Server" error and the script would stop at the 30 second mark. I increased the "max_execution_time" on my php5.ini file and the file would continue to stop at 30 seconds. I created a phpinfo.php file which showed the php settings and the changes I made did, in fact, take effect. I am pretty new at PHP so this may have been the wrong way to try and fix this but I decided to break the query up into smaller chunks using LIMIT in the query. Initially I made 2 queries in the same script with the first as "LIMIT 0,100" and the next as "LIMIT 100,100" but it didn't work. After a while looking around, I saw the php FLUSH command and I decided that I would try it out. I placed it directly between the two queries in the script as "flush();" and it worked. I really don't know why it worked but I was desperate and happy to see some progress. I was excited until I got to the fourth and fifth set of queries. Now my script times out at 90 seconds. What now? I am thinking that it may be because I am using Windows shared hosting and iis7. I hope that I am wrong because my site is at GoDaddy and I don't think have access to any of the ii7 settings. Any ideas? Here is a snippet below to explain. I would appreciate your help tremendously.




$query = "SELECT * FROM tracks WHERE id='11' LIMIT 0,100";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

while($row = mysql_fetch_array($result)){

$WSDL = 'http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx?WSDL';
$client = new SoapClient($WSDL);
$response = $client->getElevation(array('X_Value'=>$row['lng'],'Y_Value'=>$row['lat'],'Elevation_Units'=>'FEET','Source_Layer'=>'-1','Elevation_Only'=>'true')); //works

$elevations = $response->getElevationResult->any.' ';
echo $elevations;

}

flush();

$query2 = "SELECT * FROM tracks WHERE id='11' LIMIT 100,100";
$result2 = mysql_query($query2);
if (!$result2) {
die('Invalid query: ' . mysql_error());
}

while($row = mysql_fetch_array($result2)){

$WSDL = 'http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx?WSDL';
$client = new SoapClient($WSDL);
$response = $client->getElevation(array('X_Value'=>$row['lng'],'Y_Value'=>$row['lat'],'Elevation_Units'=>'FEET','Source_Layer'=>'-1','Elevation_Only'=>'true')); //works

$elevations2 = $response->getElevationResult->any.' ';
echo $elevations2;

}

flush();

$query3 = "SELECT * FROM tracks WHERE id='11' LIMIT 200,100";
$result3 = mysql_query($query3);
if (!$result3) {
die('Invalid query: ' . mysql_error());
}

while($row = mysql_fetch_array($result3)){

$WSDL = 'http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx?WSDL';
$client = new SoapClient($WSDL);
$response = $client->getElevation(array('X_Value'=>$row['lng'],'Y_Value'=>$row['lat'],'Elevation_Units'=>'FEET','Source_Layer'=>'-1','Elevation_Only'=>'true')); //works

$elevations3 = $response->getElevationResult->any.' ';
echo $elevations3;

}

flush();

$query4 = "SELECT * FROM tracks WHERE id='11' LIMIT 300,100";
$result4 = mysql_query($query4);
if (!$result4) {
die('Invalid query: ' . mysql_error());
}

while($row = mysql_fetch_array($result4)){

$WSDL = 'http://gisdata.usgs.gov/xmlwebservices2/elevation_service.asmx?WSDL';
$client = new SoapClient($WSDL);
$response = $client->getElevation(array('X_Value'=>$row['lng'],'Y_Value'=>$row['lat'],'Elevation_Units'=>'FEET','Source_Layer'=>'-1','Elevation_Only'=>'true')); //works

$elevations4 = $response->getElevationResult->any.' ';
echo $elevations4;

}

jscheuer1
09-30-2010, 01:57 AM
I don't have direct experience with this sort of thing but have done some less intensive stuff that was failing because of the server timing out. I tried com_message_pump(), but eventually settled (for now) on usleep(), which worked much better than com_message_pump():

http://us3.php.net/manual/en/function.usleep.php

to delay in a loop until I got what I wanted:


while ($browser->ReadyState!=4) usleep(10000);

In this case I'm waiting for the browser on the server to load a page so I can get a thumbnail of the page.

I have no idea if com_message_pump() or usleep() will be of any use to you here, my apologies if they aren't. But you sounded like you were willing to entertain any option that might work.

cooper30115
09-30-2010, 02:39 AM
Thanks for the reply John and, yes, I am willing to try anything. I am not sure how to apply what you have given me. I am really a novice at all of this and sometimes the solution is staring right at me and I don't see it. I may not exactly understand what is happening when I get a timeout. I have read that several things can cause a timeout.

jscheuer1
09-30-2010, 04:08 AM
I'm a novice at PHP as well, but bring to it an understanding of how presentational and programming languages work.

To try it out, I'd do something straightforward like


while (whatever you're looking for isn't here yet){
usleep(10000);
}

cooper30115
09-30-2010, 06:08 PM
Thanks for the help John but I get an error when I try to implement usleep into my code. I immediately get the "500-Internal Server" error. I am guessing that I am placing the parentheses for the while loop around something that I am not allowed to enclose. Basically all four portions of my code are in a loop already and I'm not sure if I can place a while loop in a while loop or not. Thanks again.