Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP - Execute task at predetermined time

  • 01-09-2009 03:35PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,475 ✭✭✭MOH


    AS Kopf suggested, try at


  • Registered Users, Registered Users 2 Posts: 4,846 ✭✭✭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