Cron Jobs calling PHP files not working??

Trank

Verified User
Joined
May 5, 2004
Messages
5
Howdy

I am using Direct admin ver 1.21.3 I have three Cron jobs set up properly. The paths are correct and such. When the Cron calls the files all I get are errors.

When I call the files using a browser they do exactly like they are supposed to, so I know the files are correct.

All three files are PHP files. Is there something special I have to do to the Cron call to get it to call PHP files correctly??

Any help would be much appriciated.

Thanks
 
/usr/bin/php file.php

or add the follwoing to the top of the file:

#!/usr/bin/php

Chris
 
Thanks ProWebUK for the suggestion. I tried it and this is the error I got with #!/usr/bin/php as the first line.

/bin/sh: public_html/p1/my350tpi/5min.php: /usr/bin/php: bad interpreter: No such file or directory

The original error I was getting was this;

public_html/p1/my350tpi/5min.php: line 1: ?: No such file or directory
public_html/p1/my350tpi/5min.php: line 4: syntax error near unexpected token `;'
public_html/p1/my350tpi/5min.php: line 4: `$time=time();'

The thing to rember here is that the file works perfectly when I call it from my browser. Therefor I do not believe there is anything wrong with the file or the syntax of the file itself.

A friend of mine said something about doing a wget call of some sort, but he didn't know how to do it and I have never heard of it before.

Any help is much appriciated.

Thanks
 
Thanks a bunch Chris.

It looks like putting this line in got the problem fixed #!/usr/local/bin/php

I am still getting two emails from the Cron Dameon, but now they are blank. The one file is not tripping the sending of an email. That is probly some unrelated problem.

Everything seems to be working right now except for that.

Thanks a bunch for all the help
 
Add this at the end of the cron command: (to stop the emails)

1> /dev/null 2> /dev/null

Chris
 
Howdy Chris

I want to thank you again. That took care of the emails and everything. All is working perfectly thanks to the help you gave me.

Thanks Again!!!
 
hie

Sorry! it's:

#!/usr/local/bin/php

Chris
I've added above line to my script and I changed command to :
/usr/bin/php -q/home/metaroa/domains/metaroa.com/public_html/cron/temp.php
but still it doesn't work, can you help me please?
here is a simple php code I've used to test my cron jobs:
<?php
#!/usr/local/bin/php
$f='test.txt';
$p=fopen($f,'w');
fwrite($p,'kaytan');
fclose($p);
?>
 
As I wrote in the other thread, the php command should use the -f switch, not -q.

Also the line "#!/usr/local/bin/php" should be put as first line of the script, but it's useless in your case.
 
I'm trying to run the following php code along with gd library as a
cron job ,but cron is not generating any output.
When I run this code from my browser I get an image correctly.
Somebody please tell me what needs to be done to get an image via cron
job.
<?php
//Header("Content-type: image/png");
$height = 300;
$width = 300;
$im = ImageCreate($width, $height);
$bck = ImageColorAllocate($im, 10,110,100);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $bck);
ImageLine($im, 0, 0, $width, $height, $white);

for($i=0;$i<=299;$i=$i+10) {
ImageLine($im, 0, $i, $width, $height, $white); }

ImagePNG($im,"x.png");
 
I had this problem on a non-DA server ages ago, I forget what it was now...
I think it was something to do with PHP CLI

Can you run it from shell? If so, any errors?
 
I cannot see in the code snippet where the image is supposed to be created.

I believe cron works from the user's home directory. So if the script says its going to create the image in the directory "images" then cron is going to try to create it in /home/username/images.
 
How are you calling PHP in your cron? Common mistake is not using the full path to PHP.
 
Back
Top