Results 1 to 6 of 6

Thread: php cron

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default php cron

    i found this script which checks every few minutes if a file exists.
    can anyone help me understand the highlight. it looks like a shell script but how does it trigger the php to look for the file?
    Code:
    #!/usr/local/bin/php -q
    <?PHP
    if( !file_exists( "./.pending-hup" ) )
    {
    		exit;
    }
    $qmailSendPID = intval( `ps -axw | grep qmail-send | grep -v grep | awk '{ print $1 }'` );
    if( $qmailSendPID )
    {
    		if( !posix_kill( $qmailSendPID, 1 ) )
    		{
    				echo "ERRO: posix_kill( qmail-send, HUP ) falhou.\n";
    		}
    		else
    		{
    				@unlink( "./.pending-hup" );
    		}
    }
    ?>
    Last edited by ggalan; 12-31-2011 at 08:56 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe that line says that the following code should be run using the ".../php" program-- and that the -q flag should be used. I have no idea what "q" means, though. (It's probably just a default mode, like no errors or setting a maximum time limit).

    But something else would need to make it occur every few minutes. That's just a one-time script. You can usually set up cron jobs in your cpanel or whatever equivalent you have. If not, you may need to set them up in apache directly via the command prompt.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    code should be run using the ".../php" program
    do you mean the path to php's directory?

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    yes; #!/usr/local/bin/php -q tells the server which program to use to execute the script (PHP, in this case). Most times, you don't end up needing it; but you do need to make sure that it's the correct path to your installation of php.

    the -q flag suppresses HTTP headers (since you're not outputting html, you don't want them).

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    so then this file should be saved with which extension?
    cron.sh
    or
    cron.php

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    what extension did the original script have?

    I always used the .php extension; I've never used the #! directive (though the .php extension might be the reason I never needed it).

    My instinct would be to either:
    1. keep the #! directive and save the script as cron.sh (using the CGI interface, so you'd need the directive)
    2. remove the #! directive and save the script as cron.php (simply using the cron to trigger a PHP script)
    As I said, however, I don't know for sure. You'll need to try it out and let us know how it works...

  7. The Following User Says Thank You to traq For This Useful Post:

    ggalan (12-31-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •