2

I am making an application in which once a week will have to perform multiple operations (calculations) based on all users of the system. Initially estimated about 300 users.

My question is, is there a method to perform this type of operation? like batch processing? At this moment, I test the script with only an user and on my localhost, I use a foreach cycle to cycle users and made ​​all queries, calculations and insert the results ..

I have the doubt if more users saturate the script or hosting or similar things.. How can i handle such situations?

Cheers ;)

mauriblint
  • 1,802
  • 2
  • 29
  • 46

1 Answers1

1

This kind of situation is usually done with Cron (or something similiar on Windows). So if your script is run only by cron in off-peak hours (e.g. 3am on Sunday if all your users are in one timezone), you are almost certain that it neither run twice in the same time nor does affect your users.

Since MySQL supports transaction and stored procedures and functions, I would recommend you to use stored procedure in database rather than PHP script for looping through data. You can then store logic in db functions and do something like insert-select in a transaction. It should be faster, safer and more convenient way than plain loop.

eMko
  • 1,147
  • 9
  • 22