Hi all,

Ive posted about a status bar before but have completely lost myself so im starting again 🙂

I have a website that builds a pdf (using FPDF) form a pdf library. Basically it collates pdf's and makes them into 1. When a user collates quite a few the user is faced with a blank screen for a given time...somtimes up to 5-10 mins.

What I would like to do is give them either a progress bar to let them know its still working or give them a message that pops up at the start of the process then closes when its finished?

Anyone done anything like this before?
I havent a clue where to start wil it? maybe around the Obj?

Any help or advice greatly accepted as im still in the learning phase of php.

Thanks
Mike

    This is a JavaScript deal.

    You could have a hidden layer that shows when the submit button is clicked, and then hidden again on unload (although it is kinda pointless to hide it when it will be gone when the page reloads after the file posting is finished, unless you're doing it via Ajax).

      This is tricky because there is buffering behavior between the web server and your browser. Your script might be outputting stuff like '5% done.......6%done...etc' but these updates will only get sent from webserver to browser at unpredictable intervals.

      I have managed before to write a php script that the user visits via web browser which 'forks off' another process and then returns immediately. Let's assume for a moment that you have some time-consuming script called long_script.php which you want to run. Create another script called script_launch.php which has this code:

      $start_cmd = "php long_script.php > /dev/null & echo \$!";
      $output = array(); // will contain an array of output lines from the exec command
      $result = null; // will contain the success/failure code returned by the OS.  Will be zero for a valid command, non-zero otherwise
      $return = exec($start_cmd, $output, $result); // $return will contain the last line from the result of the command which should be the PID of the process we have spawned
      
      if ($result) {
        die('We were unable to fork off the long process:' . print_r($output));
      }
      
      echo 'Process forked!  Your pid is ' . $return . '<br>';
      echo 'output:<br>';
      echo nl2br(print_r($output, true));
      

      With a bit of modification, this script could be altered to redirect to another php page which repeatedly checks to see if the other script is finished. It could simply refresh itself using a META tag.

      The trick would be to alter long_script.php so that it provides some kind of indicator about its progress. Ideally, it would use a threadsafe database like MySQL so that the two scripts, if running at exactly the same time, wouldn't both try to access the same file thereby producing an error or race conditions or some other concurrent execution nastiness.

        in a similar case, i run the job in the background, and send the user an email when their pdf is ready to be collected. then they don't have to sit there for 10 minutes; and the server is less stressed.

          Why not you use ajax stuff. Just put your pdf file creation process in a file and call it using ajax method. So using ajax method you can show any moving gif file which say working.... and when the process is done using ajax method hide this gif file.

            Write a Reply...