SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HTTP Response problem

    I have a PHP script, which executes more than 10 minutes, so I used
    PHP Code:
    set_time_limit); 
    But after getting exactly "9958526" characters response, execution is being stopped(or the HTTP connection is closed?). What could be the problem?

    I tried to execute the script 3 times and every time I got exactly "9958526" characters.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Off load the script that takes 10 minutes to run to another process that is not bound by HTTP or network protocols.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast rashedirshad's Avatar
    Join Date
    Sep 2009
    Location
    Rawalpindi, Pakistan
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    I have used set_time_limit(). Try to use the following code:

    PHP Code:
    set_time_limit(10*60);/*for 10 minutes*/ 
    Khan
    _______________________
    http://www.peoplesourceinternational.com/

  4. #4
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @logic_earth
    That is what I am planning to do if no solution is found. But, this script needs some input from the user/administrator. So I am planning to go with web page.

    @rashedirshad
    set_time_limit( 0 ); will allow to script to run without time limit.

  5. #5
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cannot go for a console script, because it uses some of the other classes of my application, which is running inside chroot. If I need to do this, I have to make lot of modifications.

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It could be your web server has a timeout limit as well

    But anything that takes that long to run should be spawned as a background job
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ArunB View Post
    I cannot go for a console script, because it uses some of the other classes of my application, which is running inside chroot. If I need to do this, I have to make lot of modifications.
    You can have your web access and to all your supporting classes, It works like this. The web front end receives a request, along with it all the data it needs to process. The front end spawns a brackground PHP script (example: shell_exec( 'php bgproc.php -- ' . serialize( $data_array ) )) to process the data while it instantly returns to the user telling the request is being processed. bgproc.php would independently access all the supporting classes it needs and process the data. Would need to implement a communication framework so bgproc.php can tell your web front end processing is done.

    Little crude explanation but I hope it helps explain. You really really want to send this long process to the background, HTTP Agents will not wait for 10 minutes to receive your response.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  8. #8
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Actually, my web server is running inside a chrooted environment. So, there, files will be included in the context of chroot environment. If I include those files, they may cause some errors because in non chroot environment, they will look for the same (original)folder structure, which doesn't exist. Files should include like "Chroot Directory Path" + path inside chroot.

    Also, I cannot use shell_exec, which is a disabled function in my environment.

    Regarding HTTP agents waiting for 10 minutes, I think I should try
    PHP Code:
    ignore_user_aborttrue ); 
    But users may not be knowing the result of the operation.

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's possible to break the job up into smaller tasks which take less time to execute, you could spread them over multiple http requests. The tasks could be done sequentially, or maybe even some could be done concurrently.

  10. #10
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If we are using MySQL transactions in that script, then you cannot split that script into multiple scripts.

    Also, I changed the maximum allowed memory usage of a script to 32M with no luck.

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Athens, Greece
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the server kills any web process that runs for more than 10 mins? If there is problem with http connection, ignore_user_abort would solve this.

    Or, maybe there is an error in the script at ~that point?

  12. #12
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that web server will stop the script if it runs more than 10 minutes if I use set_time_limit( 0 );.

    In Web server error log, I found segmentation fault. May be this error is related to my script.

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If those seg fault timestamps correspond to your scripts, there you go.

    fyi set_time_limit() is for the php internal execution timer, not the webservers. php runs as a child process of the webserver, and so php only gets to execute until the webserver sais otherwise.

  14. #14
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I do know that set_time_limit() works in the context of PHP. I also checked my Web server's (Apache) timeout configuration, it is not configured in my server and it's default value is 300 seconds. But my request is getting aborted after ~20 seconds.

    How can I know the reason for the segmentation fault?

  15. #15
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ArunB View Post
    How can I know the reason for the segmentation fault?
    The only time I've ever managed to trigger an Apache segmentation fault with a PHP script was using a regexp to determine if a string was UTF-8. Are you using any regexps?
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  16. #16
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ArunB View Post
    How can I know the reason for the segmentation fault?
    A quick Google search, returns this.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •