Cron

undead_corpse

New Member
Messages
11
Reaction score
0
Points
0
How do I run cron to a php file? I put in the URL address in the action and I get an e-mail telling me that there was a 404! :nuts: Also what protection can I put on the file so that users can run it only cron can?
 
F

Fahad

Guest
cossacks is currently down.
stoli and absolut are up and down randomly.
Normal service will be restored in a month.
As for protection, keep it out of web root
 

deadimp

New Member
Messages
249
Reaction score
0
Points
0
For CRON, you enter the path on the server (according to the *nix filesystem), not as a URL.

As fahadsadah said, you usually don't want to expose your CRON job file in your html/web directory (/public_html, /www), since the script most likely does maintainence that could be cumbersome and might be the base of a DOS attack or even a larger security risk.

I just put mine in the /etc directory. That way no one can access/execute it via normal HTTP access. [EDIT: /bin would probably be better. I think /etc is more for configuration...]
The way I have CRON execute the file is to call php and tell it to process that file - keep in mind that it's a command and not a file (unless it's a shell/executable) you're entering.

Ex: php -q /home/username/bin/script.php

Also remember that in this way PHP is not running as a CGI module, meaning you won't have access to the environment variables you're used to, like $_GET, $_POST, etc.
If you want to refine your control, keep in mind that you have access to the arguments passed to the script via $_SERVER['argv'] (which are like $_GET). You can pass commands like this: "php -q /blah/script.php -clear". If you used print_r($_SERVER['argv']), it would return Array([0]=>'/blah/script.php', [1]=>'-clear').

I don't know what the -q flag does, though... Corey had suggested it here.
Can't find it via `php --help` on my XAMPP installation.

EDIT: Got bored, decided to post a tutorial on it.
 
Last edited:
Top