Announcement

Collapse
No announcement yet.

Calling a PHP script from Cron?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling a PHP script from Cron?

    I searched this board and there was only one post that I could find that addressed the specific issue of calling a PHP script using cron. That post had me a bit confused, so I was wondering if someone could make it nice and easy for a moron like me to understand the best way to call a PHP script using Cron. Thanks!

  • #2
    The easiest way that I prefer is to compile PHP as a stand-alone binary. Then, in crontab, or in the file you want to run, do a:

    ./php myfile.php >/dev/null

    Does that help ?

    Comment


    • #3
      I'm dumb.

      So, let me try to understand. You're saying that I can't just point Cron at an existing PHP file and make it go. I need to have another version of the PHP binary, separate from the one that RedHat uses? And that binary should be in the same directory as the PHP script that I want to run? Why does it require a separate PHP install? I know I'm slow, but I will figure it out.

      [Edited by UserName on 08-31-2000 at 06:12 PM]

      Comment


      • #4
        You can point cron to the php file and have it go if the first line of the php program tells it where to find the php binary (just like perl scripts).

        But, for me, it is easier if I just compile a separate version of php. Throw it in a directory with the php scripts and set up cron to run the php binary and the file.

        http://www.geocrawler.com/archives/3...9/8/0/2561464/

        http://www.geocrawler.com/archives/3...9/8/0/2562347/

        Comment


        • #5
          This is a very old thread. I don't know if you figured it out or not but I just thought of putting repair.php into cron and noticed if I put in

          [quote]php /path/to/admin/repair.php[quote]

          it works just fine. Just adding this since others probably want to do the same thing.

          Comment


          • #6
            Here's another way to execute a php page via cron:

            13 23 * * * /usr/local/bin/lynx -dump -auth:userass http://www.defend.net/members/grab.php

            If it's not a password protected page drop the -auth:userass

            Hope that helps,

            Tim
            Five Star Review Script - Add reviews to your website!
            Mixed Martial Arts - Houston MMA Training
            Women's Self-Defense - Courses and DVDs available

            Comment


            • #7
              [QUOTE=dwh]This is a very old thread. I don't know if you figured it out or not but I just thought of putting repair.php into cron and noticed if I put in
              [quote]php /path/to/admin/repair.php

              it works just fine. Just adding this since others probably want to do the same thing.
              I think the preffered oprion is to actually run the commad line rather than the php script

              ie

              mysqlcheck -o --all-databases

              I run this nightly
              http://forums.cpfc.org/

              Comment


              • #8
                Originally posted by Dave#
                I think the preffered oprion is to actually run the commad line rather than the php script

                ie

                mysqlcheck -o --all-databases

                I run this nightly
                Thank you Dave I will try it. In fact in the end I did wind up having some problems with that cron. So should this be run in a cron as root?

                If so, are you running cpanel? I don't know the safe way to add a cron to root that won't mess up cpanel or that won't be overwritten nightly.

                Comment


                • #9
                  Originally posted by dwh
                  Thank you Dave I will try it. In fact in the end I did wind up having some problems with that cron. So should this be run in a cron as root?

                  If so, are you running cpanel? I don't know the safe way to add a cron to root that won't mess up cpanel or that won't be overwritten nightly.
                  I generally try and not run cron job's as root unless I have to, in this case I think we have to run it as root.

                  I do run a cpanel server and my contab entry is somethinglike

                  0 5 * * * root /home2/username/scripts/sql-export

                  which is a modified sql export export which at the end has

                  mysqlcheck -o --all-databases

                  HTH
                  http://forums.cpfc.org/

                  Comment


                  • #10
                    Originally posted by Tim Mousel
                    Here's another way to execute a php page via cron:

                    13 23 * * * /usr/local/bin/lynx -dump -auth:userass http://www.defend.net/members/grab.php

                    If it's not a password protected page drop the -auth:userass

                    Hope that helps,

                    Tim
                    On most *BSD based systems, the ftp program is included, which can take http files:

                    13 23 * * * ftp "http://your[email protected]/your/file.php"

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X