exec, run until finished

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas.Burman@gmail.com

    exec, run until finished

    Hi

    I call a program through exec that can take a long time to execute.
    This is fine but I would like to show some kind of animation or
    something while the program is running and when it is finished letting
    the user download the file.

    Right now I'm using code similar to this simplified example:

    ----- index.php -----
    <form method="post" action="genetat e.php" target="_blank" >
    <input type="submit" value="Generate !"/>
    </form>

    ----- generate.php -----
    <?php
    $tmpname = time() . md5("bla");

    // Writes to $tmpname
    exec("takesalot oftime $tmpname");

    $len = filesize("$tmpn ame");

    header('Content-type: application/postscript\r\n' );
    header("Content-Length: $len;\r\n");
    header('Content-Disposition: attachment; filename="' . $tmpname
    .. '"\r\n');

    readfile("$tmpn ame");
    ?>

    So what is the best way to start the exec, show an animation until it
    is finished and then send the file to the user?

  • Jerry Stuckle

    #2
    Re: exec, run until finished

    Andreas.Burman@ gmail.com wrote:
    Hi
    >
    I call a program through exec that can take a long time to execute.
    This is fine but I would like to show some kind of animation or
    something while the program is running and when it is finished letting
    the user download the file.
    >
    Right now I'm using code similar to this simplified example:
    >
    ----- index.php -----
    <form method="post" action="genetat e.php" target="_blank" >
    <input type="submit" value="Generate !"/>
    </form>
    >
    ----- generate.php -----
    <?php
    $tmpname = time() . md5("bla");
    >
    // Writes to $tmpname
    exec("takesalot oftime $tmpname");
    >
    $len = filesize("$tmpn ame");
    >
    header('Content-type: application/postscript\r\n' );
    header("Content-Length: $len;\r\n");
    header('Content-Disposition: attachment; filename="' . $tmpname
    . '"\r\n');
    >
    readfile("$tmpn ame");
    ?>
    >
    So what is the best way to start the exec, show an animation until it
    is finished and then send the file to the user?
    >
    You won't be able to do it in PHP. Flash would be one possibility. But
    you also need to have a way for the exec'd job to communicate back to
    the flash program - which won't be easy.

    This could be easier if it weren't an exec'd program - then it would be
    using the http connection. As a batch program, though, this connection
    isn't available to it.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Andy Hassall

      #3
      Re: exec, run until finished

      On 1 Jan 2007 11:48:57 -0800, Andreas.Burman@ gmail.com wrote:
      >I call a program through exec that can take a long time to execute.
      >This is fine but I would like to show some kind of animation or
      >something while the program is running and when it is finished letting
      >the user download the file.
      >
      >Right now I'm using code similar to this simplified example:
      >
      >----- index.php -----
      ><form method="post" action="genetat e.php" target="_blank" >
      <input type="submit" value="Generate !"/>
      ></form>
      >
      >----- generate.php -----
      ><?php
      $tmpname = time() . md5("bla");
      >
      // Writes to $tmpname
      exec("takesalot oftime $tmpname");
      >
      $len = filesize("$tmpn ame");
      >
      header('Content-type: application/postscript\r\n' );
      header("Content-Length: $len;\r\n");
      header('Content-Disposition: attachment; filename="' . $tmpname
      >. '"\r\n');
      >
      readfile("$tmpn ame");
      >?>
      >
      >So what is the best way to start the exec, show an animation until it
      >is finished and then send the file to the user?
      One approach; show a page with an animated gif, flush the page, run the
      long-running exec, then do a Javascript redirection when it's done (bearing in
      mind that it's not 100% reliable).

      Or move it back a step; redirect to page a with an animation and a notice to
      the user to be patient, redirect to the long-running page and rely on the
      browser not updating the page until the next one starts returning stuff.

      If the process can provide feedback on the progress, then proc_open and
      HTML_Progress from PEAR may let you get more sophisticated.

      You have a few options since it looks like you're writing to a file so you can
      always fetch that on a separate page - although that runs the risk of leaking
      temporary files if it's not a true temp file (but if it is a true temp file
      then it'd disappear anyway).

      How long does it take? You may run into maximum execution time limits as well
      as the users' impatience.

      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • Andreas.Burman@gmail.com

        #4
        Re: exec, run until finished


        Andy Hassall skrev:
        On 1 Jan 2007 11:48:57 -0800, Andreas.Burman@ gmail.com wrote:
        >
        I call a program through exec that can take a long time to execute.
        This is fine but I would like to show some kind of animation or
        something while the program is running and when it is finished letting
        the user download the file.

        Right now I'm using code similar to this simplified example:

        ----- index.php -----
        <form method="post" action="genetat e.php" target="_blank" >
        <input type="submit" value="Generate !"/>
        </form>

        ----- generate.php -----
        <?php
        $tmpname = time() . md5("bla");

        // Writes to $tmpname
        exec("takesalot oftime $tmpname");

        $len = filesize("$tmpn ame");

        header('Content-type: application/postscript\r\n' );
        header("Content-Length: $len;\r\n");
        header('Content-Disposition: attachment; filename="' . $tmpname
        . '"\r\n');

        readfile("$tmpn ame");
        ?>

        So what is the best way to start the exec, show an animation until it
        is finished and then send the file to the user?
        >
        One approach; show a page with an animated gif, flush the page, run the
        long-running exec, then do a Javascript redirection when it's done (bearing in
        mind that it's not 100% reliable).
        >
        Or move it back a step; redirect to page a with an animation and a notice to
        the user to be patient, redirect to the long-running page and rely on the
        browser not updating the page until the next one starts returning stuff.
        >
        If the process can provide feedback on the progress, then proc_open and
        HTML_Progress from PEAR may let you get more sophisticated.
        >
        You have a few options since it looks like you're writing to a file so you can
        always fetch that on a separate page - although that runs the risk of leaking
        temporary files if it's not a true temp file (but if it is a true temp file
        then it'd disappear anyway).
        >
        How long does it take? You may run into maximum execution time limits as well
        as the users' impatience.
        Thanks for all the suggestions but it looks like i'am not going to need
        them. The execution took between 30-60 seconds on my test server, but
        when I tried it on the real server it took between 1-5 seconds :)
        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        • Mladen Gogala

          #5
          Re: exec, run until finished

          On Mon, 01 Jan 2007 21:22:30 +0000, Andy Hassall wrote:
          On 1 Jan 2007 11:48:57 -0800, Andreas.Burman@ gmail.com wrote:
          >
          >>I call a program through exec that can take a long time to execute.
          >>This is fine but I would like to show some kind of animation or
          >>something while the program is running and when it is finished letting
          >>the user download the file.
          >>
          >>Right now I'm using code similar to this simplified example:
          >>
          >>----- index.php -----
          >><form method="post" action="genetat e.php" target="_blank" >
          > <input type="submit" value="Generate !"/>
          >></form>
          >>
          >>----- generate.php -----
          >><?php
          > $tmpname = time() . md5("bla");
          >>
          > // Writes to $tmpname
          > exec("takesalot oftime $tmpname");
          >>
          > $len = filesize("$tmpn ame");
          >>
          > header('Content-type: application/postscript\r\n' );
          > header("Content-Length: $len;\r\n");
          > header('Content-Disposition: attachment; filename="' . $tmpname
          >>. '"\r\n');
          >>
          > readfile("$tmpn ame");
          >>?>
          >>
          >>So what is the best way to start the exec, show an animation until it
          >>is finished and then send the file to the user?
          >
          One approach; show a page with an animated gif, flush the page, run the
          long-running exec, then do a Javascript redirection when it's done (bearing in
          mind that it's not 100% reliable).
          >
          Or move it back a step; redirect to page a with an animation and a notice to
          the user to be patient, redirect to the long-running page and rely on the
          browser not updating the page until the next one starts returning stuff.
          >
          If the process can provide feedback on the progress, then proc_open and
          HTML_Progress from PEAR may let you get more sophisticated.
          >
          You have a few options since it looks like you're writing to a file so you can
          always fetch that on a separate page - although that runs the risk of leaking
          temporary files if it's not a true temp file (but if it is a true temp file
          then it'd disappear anyway).
          >
          How long does it take? You may run into maximum execution time limits as well
          as the users' impatience.
          >
          In my opinion, long running things are not suitable for web interface. If
          you have a batch job, you can put it on some kind of a queue and
          communicate results. Having browser waiting for the data from the server
          for extended periods of time is an extremely bad practice, application
          design-wise. It is practically guaranteed to infuriate users and make them
          demand the designer's head on an aluminum platter. No need to waste silver.



          --

          Comment

          Working...