0

I need to import a lot of products to Prestashop using XML from external API. Our shared hosting has Max_Execution_Time set to 300s. The problem is adding images to products in Prestashop is very time consuming and 300s is not enough to add all the products with images in one execution time.

My plan to deal with it is to set up a cron job that will call the script every 10 minutes or so and let the script work for limited amount of time.

Is my approach correct or is there another, better standard for doing it?

I couldn't find the answer to my problem anywhere else.

Dave
  • 2,684
  • 2
  • 21
  • 38
  • Possible duplicate: https://stackoverflow.com/questions/2840711/how-to-execute-a-large-php-script – Manpreet Nov 09 '18 at 00:34
  • i would move hosts. CLI scripts have a max execution of unlimited, but your host may still stop them. –  Nov 09 '18 at 01:34
  • If you have permissions in your server but you don't want to increase this time in all the server, check this https://stackoverflow.com/a/1693860/8542657 – idnovate Nov 09 '18 at 09:22
  • @IdontDownVote what should I look for If I should change the host? Are there hosting providers that allow unlimited execution time? Or do I need to set up my own host? – Dave Nov 09 '18 at 10:49
  • @idnovate I can not do it in the shared hosting I use. – Dave Nov 09 '18 at 11:04
  • 1
    @Dave Then I would save a record as a pointer in database to know the last product processed, then next time that cron is executed it will start with the next product from the last one processed. And if it's the first execution of the day, start form the first one. – idnovate Nov 09 '18 at 12:17
  • @idnovate That is what I thought, Thanks. – Dave Nov 09 '18 at 17:07
  • any vps would be great, they are no more expensive than a shared host. –  Nov 10 '18 at 04:39
  • @IdontDownVote if you are starting a new project it's ok, but now he should migrate all the store! – idnovate Nov 12 '18 at 07:18
  • @idnovate why not, moving hosts is easy, a lot easier than dealing with a poor one –  Nov 12 '18 at 20:10

1 Answers1

0

One solution is executing the script with the php of the console to omit the directive max_execution_time or max_input_time.

Here an example of a cron run every 5 minutes:
*/5 * * * * /usr/local/bin/php /path_of_the_script/my_script.php

If this doesn't omit the time out, just edit your script and add this at the beginning of the file:
#!/usr/local/bin/php

Resulting something like this:

#!/usr/local/bin/php
<?php

// Your script code here...

PD. This depend on the server and my path used for php is the most common, but there is the possibility that it is a different one, if you have doubts you will have to validate with your hosting provider.

Rolige
  • 993
  • 8
  • 10