PHP Background task question

Discussion in 'PHP' started by x11joex11, Jan 21, 2008.

  1. #1
    Is it possible to have code that acts like a 'thread' in PHP, that I can set to always be running while my script runs. The reason for this is because the browser will drop connections if it doesn't see some kind of input after a while and I want to avoid using ignore_user_abort() for obvious reasons, not to mention my script is kid of a 'progress showing script', but the progress might not show for a while as data is coming in from URL's.

    So I ask, is it possible to create a background task like a 'thread' in php while my other code executes. I could make that thread just print out random 'dots' to keep the code from stopping.
     
    x11joex11, Jan 21, 2008 IP
  2. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    You can enter a forever loop and just keep it running, yes. It would be a different process rather than a thread so you'd not have control over it from your main program. However you can work around by sending "signals" to that daemon.
     
    php_daemon, Jan 21, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    If data is being given to the browser, it won't drop the connection. Simply set ob_implicit_flush(true); to make sure echo() or print() statements are flushed to the browser as soon as they are executed. You could also execute flush() then ob_flush() just to be safe.

    Jay
     
    jayshah, Jan 21, 2008 IP
  4. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    better, i suggest you to use AJAX, in javascript you can timely make a call to a php page to make it execute.. in this way your thread issue will also solve using javascript settimeout method...
     
    webexpert, Jan 21, 2008 IP