Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP error line 1: `<?php ?>'

Tags:

linux

php

cron

I'm attempting to setup a very simple cron job on a web host. I have cron.php set to run every minute. Right now, for testing purposes, cron.php is simply this:

<?php ?>

And now, every minute, I'm receiving the cron email with these errors:

//home/user/public_html/mysite/cron.php: line 1: syntax error near unexpected token newline

//home/user/public_html/mysite/cron.php: line 1: <?php ?>

Is this server having a hard time accessing PHP from the command line or is there some other issue I'm not seeing?

Also, I've gotten similarly weird errors when trying to add in things like echo "test"; or even just phpinfo();

like image 609
Jake Wilson Avatar asked Feb 07 '11 22:02

Jake Wilson


2 Answers

You have no shebang line, so it is trying to execute the script using the default shell.

Add #!/usr/bin/php (or wherever PHP is) to the top of the script.

like image 155
Quentin Avatar answered Sep 30 '22 06:09

Quentin


for cron jobs you normally have to specify the executable in the cmd line /path/to/executable.php //path/to/file.php

the environment is probably returning the token error because it doesnt know what php is or what to do with it

like image 37
bumperbox Avatar answered Sep 30 '22 05:09

bumperbox