简体   繁体   中英

Is cron job right for dealing with scripts that exceed the max_execution_time?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM