though many of us has asked many question related to cron jobs, let me ask my one...

I want to execute a PHP script periodically. As a cron command I'm using:

php -q http://www.example.com/cron.php?action=getA

I also tried this one:

php -q /home/myuser/www.example.com/cron.php?action=getA

It is not getting executed and not sending any mail. I set the mail ID to my gMail ID. What am I doing wrong?

  • If you execute the script directly is the mail sent?
    – Jane T
    Apr 21 '11 at 15:27
  • In CPanel there is an option to set an email id. Send an email every time a cron job runs. less » You can have cron send an email everytime it runs a command. If you do not want an email to be sent for an individual cron job you can redirect the command's output to /dev/null like this: mycommand >/dev/null 2>&1 Current Email: mygmailid@gmail.com
    – Abhishek
    Apr 21 '11 at 15:44

What you are attempting will not work as you cannot pass GET variables via the PHP command line and you need to either escape question marks or surround the string with quotes when using question marks on the command line.

This will work:

wget 'http://www.example.com/cron.php?action=getA'


How about:

wget http://www.example.com/cron.php?action=getA

are you sure you have www.example.com as your path?

execute the following in your cron.php

// current directory
echo getcwd() . "\n";

This will return you the exact directory where your cron.php file is located, and the use php -q in your cron.

I think you should use something as this on cPanel:

php -q /home/myuser/public_html/cron.php?action=getA
  • I have tried "wget example.com/cron.php?action=getA" this one also. But no mails. :(
    – Abhishek
    Apr 21 '11 at 15:54
  • Execute the line to get the folder path. And then include it with PHP -q
    – Adnan
    Apr 21 '11 at 15:57
  • u meant to say "php -q /home/myuser/pathtocronfile/cron.php"? I tried that. :( Please elaborately reply.
    – Abhishek
    Apr 21 '11 at 16:10
  • As cron commands i tried this one: wget /home/myuser/public_html/cron.php; php -q /home/ovsec/public_html/cron.php it is not working. Please help.
    – Abhishek
    Apr 21 '11 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.