Cron job to open a webpage

cron

I have a web page at http://mydomain.com/process/2909

I want a cron job to automatically hit this page every night at 2 am. I was going to get cron to run a PHP script that opens the website with CURL like so:

        $bocURL = 'http://mydomain.com/process/2909';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $bocURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $bocFile = curl_exec($ch);
        curl_close($ch);

Is there a way for me to do this directly from a cron command without having to write PHP script?

Best Answer

The command wget is a good solution for this problem if you are accessing a script on a remote server. However, if you are running the cronjob on the actual host that is "mydomain.com" you may just want to schedule crobjob to execute the code sitting at /process/2909.

For example, we have some PHP jobs that we execute with cron. Rather than using an HTTP request that could take minutes (and potentially cause timeout issues) we setup a cronjob that calls "php5 /srv/cronJobs/2909.php" - This invokes the PHP interpreter and is not subject to HTTP timeouts. Additionally, this PHP process is separate from Apache so the scheduled job will not die in case a sysadmin restarts httpd.

Related Topic