Repeat action with Cron

418 views Asked by At

I'm using my cpanel to lunch a cron action thats open a file a write Hello every minute.

But that task is not working.

This is my code :

<?php
header("Location: http://www.google.com");
$handle = fopen("passes.txt", "a");
fwrite($handle, "Hello");  
fwrite($handle, "\n");
fclose($handle);
exit;
?>

When I try to lunch the script directly in my browser it's working fine, but the cron job isn't working at all.

I've used this command to launch the script :

* * * * * * http://www.mysite.com/myfile/write.php

.

EDIT:

All your commands are not working for me.

I'm using Cron tasks in my cpanel.

4

There are 4 answers

0
Ass3mbler On

you can do this in 2 ways

if you have wget on your system:

1: * * * * * * wget -O /dev/null http://www.mysite.com/myfile/write.php

else:

2: * * * * * * /path/to/your/php/bin/php /path/to/myfile/write.php

0
BrynJ On

You need to send the request via wget, to simulate a browser request:

* * * * * * wget -q http://www.mysite.com/myfile/write.php 
0
Nanne On

Your command is not a command you could run in a shell. It should either be

php /var/www/yoursitePath/yourFile/write.php

or

curl http://www.mysite.com/myfile/write.php

I don't know what the header should do for you in a script though, can't see that having any effect whatsoever when called like this

0
Alaa On

to run this cron every minute you have to use something like this:
*/1 * * * * wget http://www.mysite.com/myfile/write.php
or
* * * * * wget http://www.mysite.com/myfile/write.php