Jump to content

[SOLVED] Execution of php file via crontab


gtvitini

Recommended Posts

Hello,

 

I am trying to execute a .php file using cronjobs but it seems I am experiencing some trouble with the syntax I use.

 

I have set up in cpanel a cronjob with the following command to be executed:

/home1/<myaccountname>/public_html/<myphpfile>.php

 

And I have created the following simple .php file (see the code below):

#!/usr/local/bin/php

<?php

echo date("F j, Y, g:i a");

?>

 

The problem is that I cannot get to execute it, as I receive the following error:

/bin/sh: /home1/<myaccountname>/public_html/<myphpfile>.php: /usr/local/bin/php: bad interpreter: No such file or directory

I would go on and try a couple of different options but I run out of permitted cronjob executions.

 

Could you please help me set up properly the cronjob??

 

Thnks.

Link to comment
Share on other sites

Should be:

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php

 

If you don't wish to receive an email each time cron runs, then:

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php >/dev/null 2>&1

 

 

Also you don't need this line for php files:

 

#!/usr/local/bin/php

 

Just use php tags for any php code:

 

<?php
echo date("F j, Y, g:i a");
?>

Link to comment
Share on other sites

OK, thanks for the input. It finally worked but with a small update in your code (replacement of option '-p' with option '-q'):

 

php -q /home1/<myaccountname>/public_html/<myphpfile>.php

 

p.s: how can I mark this topic as [sOLVED]?

Link to comment
Share on other sites

OK, thanks for the input. It finally worked but with a small update in your code (replacement of option '-p' with option '-q'):

 

Oops, sorry for my typo. I hope it didn't cause you too many headaches! :( I'll edit my post to show it corrected.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...