0

I have spend hours to search about cron execution using php but nothing works for me...i want to execute my php script after every 30 minute.. this is myscript.php

<?php
date_default_timezone_set("Asia/Calcutta");
$datetime=date("Y-m-d G.i:s", time());
file_put_contents("aaaaa.txt", "The current time is: $datetime\r\n", FILE_APPEND);
?> 

and the script I am using to execute cron command...is crontest.php

</php
$abc=array();
$dir=dirname(__FILE__);
echo exec("'*/30 * * * * /bin/usr/php $dir/myscript.php' 2>&1", &$abc); 
echo $output;
?>

I have tried many different command... like..

"'crontab -l */30 * * * * /bin/usr/php $dir/myscript.php' 2>&1"
"'crontab -l */30 * * * * php myscript.php' 2>&1"

but nothing goes in my way..I cant understand what else I can do.. Please someone help, please On executing crontest.php I am getting error "sh:*/30 * * * * /bin/usr/php /home/content/71/9988871/html/examples/myscript.php: No such file or directory"

Ashutosh Bajpay
  • 23
  • 1
  • 10
  • On running crontest.php I am getting this error.. "sh: crontab -l */5 * * * * /bin/usr/php /home/content/71/9988871/html/examples/myscript.php: No such file or directory" – Ashutosh Bajpay Nov 13 '13 at 09:58
  • It is not `php` executing a crontab sentence. Instead, it is crontab that gets scheduled (with `crontab -e` you edit it) and then it executes it through its daemon. – fedorqui Nov 13 '13 at 09:58
  • Also, edit your answer with the error message you are getting. Do not post it as comment as it is less readable. – fedorqui Nov 13 '13 at 10:01
  • first of all I need to remove the error "sh:...No such file or directory" – Ashutosh Bajpay Nov 13 '13 at 10:04

1 Answers1

0

Try setting the cron job in terminal by following the steps:

1) Open terminal

2) Run command

crontab -e

3) At end add the following

*/30 * * * * /usr/bin/php /path of cron file

This will automatically run the cron file every 30 minutes.

Jenz
  • 8,280
  • 7
  • 44
  • 77
  • I do not have access to terminal..and after all I have to do this with php because I am working on a automated application – Ashutosh Bajpay Nov 13 '13 at 10:11
  • Please check http://stackoverflow.com/questions/5134952/how-can-i-set-cron-job-through-php-script/5135390#5135390 – Jenz Nov 13 '13 at 10:17