How to run python script based on user input timer in php/mysql

Jasmeet Singh
Jasmeet Singh used Ask the Experts™
Currently built a website that contain field for user to input number in time format.user input This input goes into mysql database when button is clicked. database
I'm currently looking into how I can use this value insert by user and use it as timer to execute a python script, the python script is which will spin the motor, how can I make it work similar to cronjob. I have tried many different crontab web interface but they do not work as I would like it too. Is there any ways of achieving this? Thank You
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technology Scientist
First, you will probably want to limit the interval to hours and minutes (or increments of 10, 15, 30 minutes, or just hours), unless you are allowed to run CRON JOBS every second or minute which you will probably want to avoid anyway since you should have a buffer in place for processing.

You would set a CRON JOB to run a PHP script (this is your timer: run the CRON every X minutes) which checks the database and runs the PYTHON script and keeps track of the next job(s); in this scenario, you could batch the jobs (for example loop/queue through the jobs that are set/collide at the same time).
There's multiple approaches.

One approach can be for example:

that the php script stores tasks to be executed a mysql table and that you have a cronjob
that executes each minute and checks whether there is any task in the mysql table, that has to be executed now.
If no it aborts
if yes it executes the task

Another one is to create a long running python script (a service that has to be started on the server),
that polls regularly the mysql table and executes the tasks to be done.

For python you could use frameworks / modules like celery.
However I don't know the equivalent for php.
NerdsOfTechTechnology Scientist

Split evenly between both expert's viable solution sets.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial