Search code examples
phpcurlcroncron-task

Execute PHP file with argument using cron job


I have a PHP with mySQL website just setup recently and it needs to have a cron task running regularly in order to create records.

The link is like

www.website.com/index.php/task/cron/api_number

If placing this link to a web browser then run, it works and records can be created.

However, after setting up Cron job likes

/usr/bin/php public_html/index.php/task/cron/api_number

it didn't work and the error was like

Status: 404 Not Found
X-Powered-By: PHP/5.5.35
Content-type: text/html

No input file specified.

I followed someone's Stackoverflow guide and tried curl, with both public link and relative link but not working.

I can understand that No input file specified. means the file is not actually existing but any suggestions of what I could do?

Thank you.


Solution

  • You could use your real path to this file, e.g:

    /usr/bin/php /path/to/your/php/file/
    

    Or if you just want to trigger an URL, you could do:

    wget http://www.website.com/index.php/task/cron/api_number
    

    (no need for php if you trigger URL, just call an URL like a web browser)