HOW TO: long time tasks - launching, managing and monitoring

Discussion in 'PHP' started by ivo.pavlik, Oct 23, 2008.

  1. #1
    Hi.

    Is there any possibility to run some long-time task in background (some PHP function as some thread running on the server) and provide some status monitoring/control for user by refreshing page.

    E.g. Need to upload some big file, depending on size and connection speed, max. request time of the server can be expired. Instead, some function would run something like thread (some PHP code) which would copy the file from temporary location to some permanent location. Some page would show the status of the thread. There could be some possibility to cancel the process shown on the page.

    Is it possible with PHP (with J2EE apps it is). I want to avoid of max. request time expiration risk.

    Thanks.

    Ivo.
     
    ivo.pavlik, Oct 23, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    yes its possible..
    thats an ajax application.

    if your familiar with ajax you will notice the "onreadystatus ==4 or == 200"
    thats where this function goes in.

    try to search more on the forum, i have read these from other forums here at the philippines
     
    bartolay13, Oct 23, 2008 IP
  3. ivo.pavlik

    ivo.pavlik Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Ajax is another possibility of monitoring on client side instead of refreshing page. But I need that stuff on server side for long-time tasks (longer then request timeout). Because if the request is activated even by Ajax, timeout is still counting down :D
     
    ivo.pavlik, Oct 23, 2008 IP
  4. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you are using a shared hosting, then you cannot change max timeout as most of the hosting companies does not allow it. However, you may split the file into small equal parts and then use multiple AJAX requests to upload the files. Then after upload you can join the files. You will need a J2EE or C# application for splitting. You can join using php also.
     
    salahsoftware, Oct 23, 2008 IP
  5. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You may also ship a windows application to split the files.
     
    salahsoftware, Oct 23, 2008 IP
  6. ivo.pavlik

    ivo.pavlik Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    I have used file uploading just as a sample. Generaly, there are some tasks which processing time can expire request timeout. I need upload file via post request and use some other stuff with processing including some database operations. PHP is standard offer by webhosting providers however, Java isn't. Also, there's a need to do it with thin client. Some operations are covered with Java applet with splitting files. But splitting covers only file uploading.
     
    ivo.pavlik, Oct 23, 2008 IP