Run a php script on localhost using cron job - php

I am trying to set up a cron job on my localhost to call a php script every half an hour 24/7. Following are my steps:
1) I have created a cron.php file to call myscript.php:
<?php
echo exec('*/30 * * * * C:\BitNami\wampstack-5.4.21-0\php -f C:\BitNami\wampstack-5.4.21-0\apache2\htdocs\myscript.php');
?>
2) Created a cron.bat file to run the cron.php on browser:
"C:\Program Files\Mozilla Firefox\firefox.exe" "localhost\cron.php"
3) Then I have set up a windows 7 task scheduler to call cron.bat every day.
I welcome any idea on how to set up a cron job as my approach doesn't do anything.
Thanks

This is not an answer, but only pointers you need to check before you proceed further.
Crons are available only on unix systems, not windows.
While debugging cron or anything similar, schedule them for every minute or (any such acceptable smaller frequency), and once they work every minute, only then schedule them for the original frequencies. That will save you some time during debugging.
Its an incorrect call to exec. You don't have to pass all those * in it
Since this is windows, You want to do php.exe and not C:\BitNami\wampstack-5.4.21-0\php -f which would have been done in linux (with proper path)
Your .bat file is currently scheduled daily, you need to schedule it every half hour.

you don't need to creat .bat file to run php script
follow the step to setup cron job for php interpreter..
step 1- Then I have set up a windows 7 task scheduler to call php script by giving path of php interpreter like C:\xampp\php\php.exe filename.php by setting desired interval

dude, you cannot define cron jobs in wamp,
the cron is a linux feature and you are running the wamp on windows.
you can run the script from the command line (of from cygwin, much better),
something like "/php.exe "
but you cannot define crons on wamp
but you can setup the scheduler to run a .bat file that contains the next code
cd/
cd "Program Files (x86)"
cd GnuWin32
cd bin
wget.exe http:// localhost/... (your file)
echo DONE

Related

How to run php script on cron job in cpanel

I schedule a new job on cronjob. But it's not working. Is there any way to run cronjob in cpanel using commands.
There is a bunch of way to running script with CRON. I do use this way on my web application most of the time when I need to use CRON.
The first step is to choose a setting. The setting means when you want to run this script.
and after then simply just use CURL with Cron to get this work properly like this: curl http://example.com/script.php on command box and click on the add button and whola! You have successfully added your first CRON Task.
You may have a look at this picture below to get it properly
Go to CRON JOB option on your cpanle menus
Set url like this and set time according to your functionality
php /home/username/public_html/filename.php
Run it in putty
/usr/bin/php /var/www/html/project_name/artisan schedule:run 1>> /dev/null 2>&1 this is for laravel project
you can simply use like this - /usr/local/bin/ea-php74 /home/username/domainname.com/script_path/yourfile.php
replace username to your cpanel username, domain name to your domain name, script path where you want to run it, then replace the main file for corn job in yourfile.php

Shell script runs php files over and over again

I have a ridiculously simple shell script, nothing more than a few instructions to run some php files ...
#!/bin/bash
clear
cd /home/************** // Just for privacy here
php cron-cpt.php
php cron-lvt.php
php cron-plots.php
php cron-m.php
php cron-a.php
The script is called metrics.sh which is chmod'd and just sits in my local binary folder.
If I run the script from the command line, it works perfectly.
If I add the same script to the cron tab to run once a day, it runs over and over. I assumed the cron was the same as invoking it manually from the command line?
I'm using the same user to invoke in cron as logged on cmd line and have tried as root and a standard user, but the same results prevail.
Google has not been helpful with this. Any suggestions?
Add this to your cronTabs:
0 1 * * * /home/metrics.sh
Change the location to your metrics.sh's location.

How to create a cron job in cpanel to run a PHP file every hour?

First time I am creating a cron job in cpPanel to run a PHP file every hour.
My cron command is:
/usr/local/bin /home/simplemediaplaye/public_html/new.php
What things am I missing here? This file runs well manually, but not by a cron job. Can you suggest what I need to do to run my cron successfully?
Hello If I am not mistaking, you're missing the "-q" command and PHP ? see below:
/usr/bin/php -q /home/simplemediaplaye/public_html/new.php
Let me know if that helps.

Execute PHP script in cron job

In our centos6 server. I would like to execute a php script in cron job as apache user but unfortunately it does not work.
Here is the edition of crontab (crontab -uapache -e)
24 17 * * * php /opt/test.php
and here is the source code of "test.php" file which works fine with "apache" user as owner.
<?php exec( 'touch /opt/test/test.txt');?>
I try to replace php with full path of php (/usr/local/php/bin/php) but also it doesn't work.
Automated Tasks: Cron
Cron is a time-based scheduling service in Linux / Unix-like computer operating systems. Cron job are used to schedule commands to be executed periodically.
You can setup commands or scripts, which will repeatedly run at a set time. Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron./* directories. It also checks the /var/spool/cron/ directory.
Configuring Cron Tasks
In the following example, the crontab command shown below will activate the cron tasks automatically every ten minutes:
*/10 * * * * /usr/bin/php /opt/test.php
In the above sample, the */10 * * * * represents when the task should happen. The first figure represents minutes – in this case, on every "ten" minute. The other figures represent, respectively, hour, day, month and day of the week.
* is a wildcard, meaning "every time".
Start with finding out your PHP binary by typing in command line:
whereis php
The output should be something like:
php: /usr/bin/php /etc/php.ini /etc/php.d /usr/lib64/php /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz
Specify correctly the full path in your command.
Type the following command to enter cronjob:
crontab -e
To see what you got in crontab.
EDIT 1:
To exit from vim editor without saving just click:
Shift+:
And then type q!
I had the same problem... I had to run it as a user.
00 * * * * root /usr/bin/php /var/virtual/hostname.nz/public_html/cronjob.php
You may need to run the cron job as a user with permissions to execute the PHP script. Try executing the cron job as root, using the command runuser (man runuser). Or create a system crontable and run the PHP script as an authorized user, as #Philip described.
I provide a detailed answer how to use cron in this stackoverflow post.
How to write a cron that will run a script every day at midnight?
I tried all combinations with PATHs, but don't work. Probably they are needed.
In my case, with Centos 7, a reboot or server worked.

cron job is not running on cpanel server

I am trying to run following script in cron job section of cpanel but i am not getting any mail and my database is also not getting updated as script updates the database.
/usr/bin/php /home/allsamac/public_html/getlinks/abc.php
php -q /public_html/getlinks/abc.php
In crontab system :
1./usr/bin/php is php binary path (different in some systems ex: freebsd /usr/local/bin/php, linux: /usr/bin/php)
2./home/username/public_html/cron/cron.php should be your php script path
3./dev/null should be cron output , ex: /home/username/stdoutx.txt
So you can monitor your cron by viewing cron output /home/username/stdoutx.txt

Categories