4

I have found many questions and articles about this but i still have some difficulties. I'm using the following command /usr/bin/php home/domain.com/public_html/cron/script.php I receive the following error Status: 404 Not Found X-Powered-By: PHP/5.2.8 Content-type: text/html

No input file specified.

i'm using Cpanel, the file is hosted on domain.com/cron/script.php Anyideas, thanks :p

5 Answers 5

11

Put a leading slash on the script name, i.e.

/usr/bin/php /home/domain.com/public_html/cron/script.php

Unless you actually intend to run the script through the web, as in lacqui's answer, and you don't mind random third parties being able to run it any time they like, there's no reason you should put it inside your public_html directory; quite the opposite.

Sign up to request clarification or add additional context in comments.

4 Comments

I'll add here because it's probably not obvious to OP: by random third parties being able to run it 'any time they like', I also mean 'many times a second'. Since CPU-intensive and memory-intensive tasks are often candidates for cron jobs, you may be handing people an easy denial of service attack.
Only if you don't make sure it isn't already running first. Use your database to create a guard "CRON last started at " timestamp. Then in your cron don't run if the timestamp is X minutes/hours old.
actually this might not work. you better use cd /home/domain.com/public_html/cron/ && /usr/bin/php script.php to setup working directory correctly
The job will not run in non public folder. For example /home/username/etc/cron.php does not work but it works if put in public folder.
7

Try:

wget -O - http://domain.com/cron/script.php

and see if you get a better result.

Edit: added "- O - " to not write output to home folder.

2 Comments

Mine may work, but you may want to look at chaos's better-reasoned answer.
This works well form me! as my PHP Script has some command coding as well to schedule the emails. Thanks @Lacqui
1

You might need to use the binary known as php-cli instead of just php.

2 Comments

That's for windows, in *nix you just use /usr/bin/php. And by the mention of cron its definitely *nix environment.
@cemkalyoncu: Some systems ship a seperate php-cli that contains extra stuff like readline, and others. Can come in handy on the command line.
1

I'm realising that it is an old question and that you may have found a solution but none of the answers above helped me and I was getting the same 404 error when I was running a cron script.

The problem was related to the way in which the path to the php script was written. The path must start from public_html like this /usr/bin/php public_html/public/index.php

Comments

0

In several shared hosting wget and curl commands are not available from cron. If one wants to execute a web (http) request from cron, then it can be done by calling the desired web url as php curl inside cron php script.

Below is an example code to be put inside cron php file:

<?php
function callRemoteHttp($url)
{

    $curl = curl_init();    

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);
    $ret_arr = array('data' => $result, 'status_code' => curl_getinfo($curl, CURLINFO_HTTP_CODE));
    curl_close($curl);

    return $ret_arr;
}
$ret = callRemoteHttp('http://example.com?param1=value1&param2=value2');
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.