Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    17

    Unanswered: How to run PHP Script in Background?

    hi all,

    i have one PHP page which took more than 10 mins to execute. i want it to run in the background so user can access the site normally.

    how can it be achieved in the Linux as well as in the Win Platform?
    i have search through all possibilities but none of working. i have also tested this fragment of code but it's not working.

    Main.php
    --------------------------------------
    <?
    error_reporting(E_ALL);
    if(file_exists("log.txt") && chmod("log.txt",0777))
    { print "Permission Granted<br />"; }
    if ($fp = fopen("log.txt", "a"))
    {

    print "File Created<br />";
    fwrite($fp, "Main process finished at ".date("H:i:s", time())."!\n");
    fclose($fp);
    exec("./php child.php > /dev/null &");
    }
    else
    {
    print "File Not Created";
    }
    ?>


    child.php
    ------------------------------------------------------
    <?
    if(file_exists("log.txt")) {chmod("log.txt",0777);}
    if ($fp = fopen("log.txt", "a"))
    {
    fwrite($fp, "Child process finished at ".date("H:i:s", time())."!\n";
    fclose($fp);
    }
    ?>


    pls help to get rid of this.
    thaks in advance.

  2. #2
    Join Date
    Jan 2005
    Posts
    68

    easy ajax

    you should check out prototype 1.4, a really easy to use ajax framework. you can call your script and have it run asyncronously.

Posting Permissions

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