Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default PHP controlling crons?

    Heyyy ,
    Does anyone know how i can get PHP to run a cron job that will execute a script on the first of every month?
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Jul 2008
    Location
    Ellesmere Port
    Posts
    440
    Tokens
    0

    Default

    create a file called crons.txt
    put the WHOLE cron (including the * * * * * stuff, etc) you want to run it in
    and in the same directory, create a php file that has the following contents in it:
    PHP Code:
    <?php exec("crontab /directory/to/crons.txt");?>
    then save + go to the file in you browser, then delete the file
    Last edited by NN-Dom; 15-09-2008 at 03:23 PM.

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    so i could run that on installation?

    And what code do i need to run a php file (in the crons.txt thing)
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Also how would i go about editing existing crons that are set up?
    Coming and going...
    Highers are getting the better of me

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Not all systems allow the use of crontab or exec() in general.

    It depends on the user that Apache/cPanel is runinng on, and what permissions they have, if they have permission to edit the crontab from PHP/that user.

  6. #6
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Is there a way of finding out if a site is allowed use of crontab ? Like i could do something where if their not allowed, the option to enable the cron services is disabled or something like that?
    Coming and going...
    Highers are getting the better of me

  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    you *might* could do something like this, not sure if exec returns true/false though.

    PHP Code:
    <?php
    if(exec"blabla" ) == false) {
        exit( 
    "ERROR! Could not access crontab.  Please do this step manually." );
    }
    ?>

  8. #8
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by php.net - exec() function

    Return Values

    The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

    To get the output of the executed command, be sure to set and use the output parameter.
    Apparently not ;p

    hm it might just be easier to use a system LIKE pseudocron instead..
    More control and cross-server compatability that way.

    What you guys think?
    Coming and going...
    Highers are getting the better of me

  9. #9
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    Add the cron in cpanel cron manager.

    IIRC you need:
    php -f /path/to/script.php

  10. #10
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Il just use a pseudocron like method ;p

    And ryan - if i were to use crons it would have to be controlled by the script
    Thanks anyways guys
    Coming and going...
    Highers are getting the better of me

Posting Permissions

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