3

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?

luchaninov
  • 6,792
  • 6
  • 60
  • 75
devugur
  • 1,339
  • 1
  • 19
  • 25
  • 1
    time() at start and in the loop – splash58 May 28 '16 at 08:16
  • Why are you doing this on user interaction and not in e.g. a cron? Also, updating a mere 2000 products I don't feel should take anything like 20 seconds, let alone for only 100. – Jonnix May 28 '16 at 08:18
  • Yes i can use time() in a loop, is this not problem for a server? – devugur May 28 '16 at 08:28
  • @JonStirling This is a module for ecommerce system. I was try give a cronjob information but here all users don't know how to make a cronjob. – devugur May 28 '16 at 08:30
  • @user5510975 call time() 1000 times an look to time of execution. I think it will be small – splash58 May 28 '16 at 08:36
  • 20 seconds to update 100 records sounds like your query is doing rather a lot of extra work and needs to be examined. – Nicholas Alexander May 28 '16 at 10:10

1 Answers1

2

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

luchaninov
  • 6,792
  • 6
  • 60
  • 75