abu abu
abu abu

Reputation: 7062

Script execution time in PHP

I would like to find out script execution of my script. I used the below code.

$time_start = microtime(true); 

//Here is a script which is extracting almost 13,000 product using an API

$time_end = microtime(true);    
$execution_time = ($time_end - $time_start)/60;
echo '<b>Total Execution Time:</b> '.$execution_time.' Mins';

This script is working well in localhost but it is not working in Production Server. On the other hand if I reduce the product quantity to 4,000 then it is working in production server.

Why is it happening so??

Thanks

UPDATE

If I add echo 'mouse'; at the end of the script then it is also not printing.

Upvotes: 1

Views: 162

Answers (2)

Vincenzo Petrucci
Vincenzo Petrucci

Reputation: 865

Something is happening before the end of the script. Maybe a time out. Make sure that your maximum execution time is high enough.

If your running your script from console check the max execution time with this:

php -i | grep max_execution_time

Remember that php.ini for console could be different from that used by the web server.

If it's not an execution_time issue try to be verbose in the code block where you extract products. Something like:

echo "Extracting product ".$i." (".(microtime(true) . $time_start).")\r\n";

This way you can see on your console what's going on and how the time is spent.

Upvotes: 0

Tarun Upadhyay
Tarun Upadhyay

Reputation: 724

It might be the case that your script is facing a time out.

So, please try to add time out limit at the very top of your script file.

set_time_limit(0);

$time_start = microtime(true); 

//Here is a script which is extracting almost 13,000 product using an API

$time_end = microtime(true);    
$execution_time = ($time_end - $time_start)/60;
echo '<b>Total Execution Time:</b> '.$execution_time.' Mins';

Upvotes: 1

Related Questions