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

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
Jasmeet SinghAsked:
Who is Participating?
NerdsOfTechConnect With a Mentor Technology ScientistCommented:
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).
gelonidaConnect With a Mentor Commented:
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 ScientistCommented:
Split evenly between both expert's viable solution sets.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.