0

I've already setup and finished coding the conversion of images from jpeg/png to webp. I will be using it to convert hundreds of images. But PHP has a timeout limit and changing it into large number is a bit unorthodox (or is it?). Right now the way I do it is a execute the page using a browser then it start converting but then it reaches the timeout limit before converting all images so I have to refresh the page so it will start converting again. This is working already. It just doesn't feel right, so my question is, do you have any suggestion to do it more appropriately? or maybe more conventional?

Hope someone can help me.

Thanks

Jed
  • 1,054
  • 1
  • 15
  • 34

1 Answers1

2

Some measures you can take:

  1. Execute PHP via the command line instead of via a web browser. The command line version has no maximum execution time limit.
  2. Break the job into chunks. Figure out a way to break up the images so that you can convert batches at a time.
  3. Consider implementing an asynchronous job queue. If you are converting these images in response to a user interaction with your website, consider scheduling the conversion to run asynchronously via a job. This will also allow you to take advantage of point 1 above.
  4. Consider running the script on a different server. You don't neccessarily have to run jobs like this on your production web server. You can set up a separate server just for doing this kind of operation so that it doesn't take processing power away from your users. It could even be a temporary server that use use and shutdown afterwards if the conversion is not going to occur frequently.
sg-
  • 2,196
  • 1
  • 15
  • 16
  • With solution no. 1, do you mean I should access the page using the command line? I think I should just go with it. The other answers are not applicable to me. – Jed May 30 '16 at 03:42
  • Sorry I forgot to say I'm using Laravel so I'm actually accessing the route not the php file itself. Is it executed differently? – Jed May 30 '16 at 03:52
  • You can still invoke the route via the command line. See: http://stackoverflow.com/questions/28866821/call-laravel-controller-via-command-line – sg- May 30 '16 at 03:56
  • Remember to look out for the SVG and MVG files. Most preferably disable them by checking magick bytes and setting up policy file. In older versions of IM just delete the appropriate .so libraries. Detailed vulnerability is described here: https://imagetragick.com/ – rostok May 30 '16 at 08:17