I want to send schedule based php script…
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
You can do this to run command every midnight:
<br>crontab -e (This opens the crontab editor)
<br>0 0 * * * your_command_here >/dev/null 2>&1
<br>This will run your specified command at 12 AM midnight according to local server time.
Kamal, I’m confusing now. my url is working fine via CLI. Eg: http://mydomain.com/cron/sendEmail. I tested in cmd. Now I want to run this url everyday midnight automatically. I successfully installed ubuntu and nginx only. Now what are the steps I have to do? Thanks in advance.
@farhan.sheron that solution is over engineered for a problem as simple as yours. Just add it in manually, you don’t need to code a cronjob manager in php.
Thanks kamal & Mika singh. I found an excellent article.
Create a crontab like this:
<br>curl -v http://mydomain.com/controller/function.php >/dev/null 2>&1
<br>That should do it. I am presuming you know how to create a crontab. If curl isn’t installed, install it by typing: apt-get install curl
<br>Set a cronjob that runs the following command:
<br>php -f /path/to/index.php controller function
Thanks Kamal. My script doesn’t support running from the CLI. I’m using codeigniter framework. I want to run like http://mydomain.com/controller/function. Is it possible?
<br>Any idea pls…
Does your script support running from the CLI? (“php -f /path/to/your/script.php”)