www.webdeveloper.com
Results 1 to 5 of 5

Thread: Timeout question

  1. #1
    Join Date
    Jun 2004
    Posts
    220

    Timeout question

    Hi

    I have created a class that does a lot of different things. One of these thing is launching an external exe-file (windows), using wsh shell instead of phps exec(). My problem is that I do not know how long time the exe-file will use, it can be everything from 5 seconds to 30 minutes. A web user will not want or be able to wait for 30 minutes, so I was thinking about quitting the operation after 30 seconds and put the stuff to be done in a queue, which a scheduled job using the same class can do as a background process.
    Is there a way of knowing that the execution of the external exe has used 30 seconds, and then launch a "timeout-function" which will put some stuff in the db to let the background process know something is in the queue, and then exit the current script?

    Thanks
    Lubox

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by Lubox
    Is there a way of knowing that the execution of the external exe has used 30 seconds, and then launch a "timeout-function" which will put some stuff in the db to let the background process know something is in the queue, and then exit the current script?
    No! Php is a single thread language so that is not possible. The only option I can see is to open a socket in non blocking mode and use a loop/sleep cycle to test for output, giving up after a predetermined number of attempts.

  3. #3
    Join Date
    Jun 2004
    Posts
    220
    Ok, that sounds like something I could do. I can launch the external exe in asynchron (?) mode (launch and return to script). The script can then try for 30 seconds to read a file the external exe can drop. If its not there, I can add it to the background queue, and return control to the calling script.

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by Lubox
    return control to the calling script.
    Here's the problem: the exe file is going to continue until it is finished whether php times out or not. A better way if you don't need the return value from the exe file would just be to feed it good data, set it running and then forget about it, knowing it will do its stuff in good time.

  5. #5
    Join Date
    Jun 2004
    Posts
    220
    Yes, the exe will continue and that is ok. But I need its return value, that is why I will add the stuff to a queue which the background process will take care of. I will check if wsh has some methods of killing the exe, but it doesn't really matter. I've tested this new stuff now and it's working good.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles