SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2006
    Location
    Queensland, Australia
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Browser Timeout while PHP Script Continues to Run

    I've made an ftp script which works great. I've set ob_implicit_flush to true so the 'files copied' list updates in real-time. The only proably is, when the script hits a large file which takes over a minute to process, the browser stops loading the page (firefox says 'Done').

    I know what would fix this, but i don't know how to do it. Is there are way to make php send some kind of packet every 30 minutes to tell the browser that stuff is still happening? As far as I'm aware though, it's not possible for php to do two things at once.

    Any help would be much appreciated!

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,252
    Mentioned
    161 Post(s)
    Tagged
    1 Thread(s)
    There are two things you could do.
    1) You could actually have your PHP script start a background process to do the FTP'ing information and then just periodically check up on the background process to see where it is at. Is it finished?, still running?, etc.
    2) You can alter the max execution time of your script in the php.ini file, but again, the user may stop the execution of the browser or the browser may quit on you as well.

    As for #1, you can do this in a variety of ways, with or without AJAX (depending on comfort level). Ideally, you will create a shell script or a php script to run as a system command that takes parameters or reads a file of data. Your PHP script would then use the system() or exec() placing a '&' at the end of the command to have it run in the background.

    The script it kicks off would then write a log out on the system for your client script to read and output to the user, until the process is finished (this is where Ajax or just an automated refresh interval would play in).

    Matt


Bookmarks

Posting Permissions

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