I want to add cron job dynamically once user install a php application on their server, like admin configuration, I need to set cron job dynamically once going thought its configuration settings in php?
I am using codeigniter to set the cron job, also I added the same from cpanel manually and it is working fine.
4
Answers
Hi thank you for the replies, i got my answers now, based on the replies I tried to add a new cron job to crontab file using php (codeigniter): following is my answer
This will add a new cron job without deleting anything on the current cron job file
You can create a file in
and use PHP’s
file_put_contents()
to update the file. However, you’ll need to elevate PHP or Apache’s permissions (depending on your PHP handler). This isn’t recommended since it leads to security issues.If you’re using Cron to run PHP scripts, then you can call the scripts directly using PHP every X amount of time. Create a variable in your database representing the last time your script was run. If X amount of time passed since the script was run, then you run the script and update the variable.
If the script takes a long time to execute, then use PHP to run it in a separate process, so the user doesn’t have to wait for it to finish.
Thanks
you can do this using shell script
you can use these functions or class
First You have to create one txt file for example crontab.txt
then you have to use shell script like below
And Lastly, you have to execute that file like
Hope this will help you.