Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I define time limit for one function in PHP?

I'm making module for a PHP ecommerce system. This system database have a 2000 products. I need to update all products(some values) in a one day. I dont want to update all products one time.

I try update every period 100 products when the visitor open some page (module is hooked init - header). Here i want to give time limit. If this 100 product don't update in 20 seconds make break and write last updated product id to database.

How can I do this? How this function know 20 seconds later break?

like image 453
devugur Avatar asked May 11 '26 06:05

devugur


1 Answers

You can set time limit for the whole PHP script. So you can move out this function to separate script, set time limit there and run it as sub-process.

I recommend using Symfony Process component (can be used without Symfony):
http://symfony.com/doc/current/components/process.html

Using it you can even set time limit from your main process:
http://symfony.com/doc/current/components/process.html#process-timeout

like image 62
luchaninov Avatar answered May 12 '26 20:05

luchaninov