Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP - Execute task at predetermined time

Options
  • 01-09-2009 4:35pm
    #1
    Registered Users Posts: 1,086 ✭✭✭


    With my website I have to set it so the client can insert a certain time. On this time a task will be completed which emails them.

    It should work similar to a Cron job only no repeat tasks and must be possible to create from PHP code.

    For example I might need someone to enter their email and time they want to be emailed. Then the server will execute this command at the time which was entered by the client and email them the results.


Comments

  • Closed Accounts Posts: 207 ✭✭johnl


    Either generate
    Cron jobs or else you'll have to
    Keep a daemon up.


  • Registered Users Posts: 1,086 ✭✭✭Peter B


    johnl wrote: »
    Either generate
    Cron jobs or else you'll have to
    Keep a daemon up.

    Is it possible to create once off cron jobs?


  • Closed Accounts Posts: 681 ✭✭✭Kopf


    Peter B wrote: »
    Is it possible to create once off cron jobs?

    Yes of course it is.
    Simply use the "at" command
    instead. Keep reading!


  • Closed Accounts Posts: 1,388 ✭✭✭Señor Juárez


    crontab PHP
    is really not the best, but
    beats PHP threads.


  • Registered Users Posts: 1,086 ✭✭✭Peter B


    Hey guys,

    Thanks for all the info so far. I have been doing a bit of googling but I still haven't full knowledge of how to set up these cron jobs via the command line. I can't find any code how the cron job must be deleted after it runs (as it is only needed once).

    Anybody have any sample code or know of a good tutorial to get info from.

    Thanks

    Peter


  • Advertisement
  • Registered Users Posts: 1,086 ✭✭✭Peter B


    I have got this far with manually creating a cron job. I can't seem to get it to work. When I paste the outputted code into the SSH I get
    -bash: 06: command not found
    

    // $expirydatetime is a timestamp;
    $min = date("i",$expirydatetime);
    $hour = date("H",$expirydatetime);
    $day = date("j",$expirydatetime);
    $month = date("n",$expirydatetime);
    $dow = date("N",$expirydatetime);
    	
    $commandline_expression = $min." ".$hour." ".$day." ".$month." ".$dow." /var/www/vhosts/exsite.name/subdomains/tipoff/httpdocs/autosend.php?d=".$dealid;
    echo "<br />".$commandline_expression."<br />";
    //exec($commandline_expression);
    


  • Closed Accounts Posts: 3 mahack3r


    Use crontab to set up a once per minute call to "php script.php". In the script get the current time and select all jobs that are before this time.


  • Registered Users Posts: 6,465 ✭✭✭MOH


    AS Kopf suggested, try at


  • Registered Users Posts: 4,769 ✭✭✭cython


    If this is to be done all through PHP, and depending on the server access you have, you might find pseudo-cron useful


Advertisement