Keeping a script running server side at all times [closed]
-
26-12-2019 - |
Question
I have created a website: http://instapromobiz.com that automates Instagram likes/follows/unfollows via Instagrams api mainly using javascript and a little php.
My issue is that clearly it only runs while the user has the page open. This may be a broad question, but what would be the best way to have this script(which is an infinite loop until the user stops it) run without the user having the page open. Basically they log on, add tags and press start, then they can leave, then come back later and stop the script.
I have regular web hosting, no SSI or VPS, so node.js can't be used.
Solution
Rrestructure your script to terminate, and then use cron to run it every minute or every 15 min. Many web hosting plans will support this type of configuration.
More info on Cron: https://help.ubuntu.com/community/CronHowto
OTHER TIPS
You can accomplish this in PHP versions 4 and 5.
Step 1. Remove the time limit
Use the set_time_limit function, and call this:
set_time_limit(0);
Step 2. Ignore the abort
PHP has a friendly function called ignore_user_abort. Use it like this:
ignore_user_abort(true);
Now, the script can run forever!