I showed how to make a file for setting cron job handled by command line ( Click Here To see the previous post ). There are a limitation of that way which is “for every cron we should make a new file“. Here we will see how can we make a common file where any amount of cron can be handled by the file.
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
/* set some constants */
$_SERVER['QUERY_STRING'] = $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = '/' . implode('/', $argv) . '/';
Here we are using PHP’s $argv variable to get a list of the arguments, so if I called the script by saying:
-f path/cron.php cron sendmail
…then $argv would be an array with the elements of “cron.php”, “cron”, “sendmail”. We don’t need the first element, so unset that. Then implode the rest of the elements to form the request path, and the end result would be /cron/sendmail/, same as the before.
So you just need to call the file like follows:
/usr/bin/php -f /home/user/public_html/cron/cron.php controller_name function_name
Hope you are clear about the idea.