Hi.
I found this post relevant to the point I wish to get some insights on: Long server action freezes up the entire website
Similar to what is described in the post, I too have created an extremely long running SA which synchronises my DB copy of Shopify product data. It may take anywhere from 3 to 10 minutes to complete.
The concept is pretty much similar:
- Fetch a set of product IDs from DB.
- For each ID, hit Shopify API to fetch product variant information.
- Upsert the response in another DB table.
- Keep repeating for each ID until done.
- Run this script periodically using CRON jobs.
While running this, what I discovered is that after 120 seconds, I was being returned a “connection timeout” error from the server.
I ran this SA directly in the browser/postman as an API call to test and also via cURL in terminal.
After a long discussion with my hosting provider, I discovered two things:
- There is something called webserver timeout, apart from PHP’s max execution timeout setting.
- An API call should not last more than 120 seconds - 2 minutes - as a recommended approach. Nothing wrong with it itself, but a long running call means blocked resource for other API calls and requests on the webserver.
- I played around with script timeout settings in Wappler SA, as well as PHP INI settings - but at the end, it was web server timeout that made the difference.
So here’s what I would like from the team and community to help me with:
- Has anyone had any experience with running long scripts in PHP via cron job or API call with Wappler or otherwise? What do you recommend?
- Is there any way to run a SA PHP file directly from terminal, without having to use cURL? SA provides an extremely easy and secure way of building out complex stuff. So I wish to use SA to build my set of tasks and not use core PHP.
- Is there any other way to handle the task of synchronizing data from a 3rd party API (like Shopify) into my own DB other than long running PHP script? I have though about breaking it into batches, but could not figure out a Wappler-based way of doing it.
Using PHP & Wappler are constants - I would not go around this unless the other method is extremely rewarding.
Last updated: