How do i execute a php script in cron jobs.

Usually you give unix commands for a cron job, but how do i run a php file in a cron job.

I'll explain this in little detail.
I am developing a website which sends mail to its subscribers every Sunday night by 2400 hrs and also do some processing with the data in the table. Hence the php script is too big. I want to do different jobs at different time intervals, hence need for a cron job. The problem i face is in executing the php files with the codes.
I have the files with .php extension. I think i'll need to write a shell script. Do let me know of how to do this?
Also let me know whether it is necessary to have this script file at a particulat folder say /etc etc.
Thanks

    • [deleted]

    Get yourself a CGI version of PHP (read the manual on how to get one)
    and run it like any other crob job.
    php -q /path/to/file.php

      If you cannot get a cgi version of PHP then you can simply call a text-based web browser from within cron to execute your page. Here is an example where I use w3m to execute my script:

      0,30 /usr/local/bin/w3m -dump http://www.freshnews.org/php-bin/slash.php >/dev/nu
      ll 2>&1

        If you cannot get a cgi version of PHP then
        you can simply call a text-based web
        browser from within cron to execute your
        page. Here is an example where I use w3m to
        execute my script:

        0,30 /usr/local/bin/w3m -dump http://www.freshnews.org/php-bin/slash.php >/dev/nu
        ll 2>&1

        What is w3m? Does it come along with linux? or do i need to have it separately? Give me few ideas regarding the same.
        Thanks for your suggestions.

          I don't think w3m is a standard linux utility, but I know that lynx is. Lynx can be used the same way as w3m. The only reason I use w3m is because my hosting service does not offer lynx. All you would do is set up a cron job to have lynx hit the php script. It will execute it for you.

            Write a Reply...