开发者

php - how to determine execution time?

I have to process more i开发者_StackOverflow社区mages with big amount, (10 mb/image)

How do I determine the execution time to process all of the images in queue?

  • Determine the time base from the data that we have.

  • Set the time limit.

  • Run process.

And what do the execution time depend on? (Server, internet speed, type of data...?)

@All: i have changed my way to do my issue, send 1reqeust/1image,

so with 40 images, we will be have 40 request. no need to care about excution time :D

Thanks


You can test your setup with the code

// first image
$start = time();
// ... work on image ...
$elapsed = time() - $start;

if (ini_get('max_execution_time') > $elapsed * $imageCount)
    trigger_warning("may be not able to finish in time", E_USER_WARNING);

Please note two things: in the CLI-version of PHP, the max_execution_time is hardcoded to 0 / inifinity (according to this comment). Also, you may reset the timer by calling set_time_limit() again like so:

foreach ($imagelist as $image) {
    // ... do image work ....

    // reset timer to 30
    set_time_limit(30);
}

That way, you can let your script run forever or at least until you're finished with your image processing. You must enable the appropriate overwrite rules in the apache-configuration to allow this via AllowOverride All


I would suggest (given your limited info in the question) that you try using the trial and error method - run your process and see how long it takes - increase the time limit until it completes - you might be able to shorten your process.


Be aware that the server processing time can vary a LOT depending on the current load on the server from other processess. If it's a shared server, some other user can be running some script at this exact time, making your script only perform half as well.

I think it's going to be hard to determine the execution time BEFORE the script is run.

I would upload batches (small groups) of images. The number of images would depend on some testing.

For example, run your script several times simultaneously from different pages to see if they all still complete without breaking. If it works with 5 images in the queue, write your script to process 5 images. After the first five images has processed, store them (write to database or whatever you need), wait a little bit then take the next 5 images.

If it works when you run three scripts with 5 images each at the same time, you should be safe doing it once with whatever some other user on the server is doing.

You change the time execution time limit in the file php.ini, or if you don't have access to the file you can set it in on the fly with set_time_limit(600) for 600 seconds. I would however write smarter code instead than relying on time limit.

My five cents. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜