-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implemented fastcgi_finish_request #113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the php documentation has a comment about blocking trough session, but I dont think sessions are really blocking. (actually they even have problems with multiple parallel requests writing into the session)
But that problem would still exist without this addition
// to the client open. | ||
if(php_sapi_name() == 'fpm-fcgi' && true === function_exists('fastcgi_finish_request')){ | ||
fastcgi_finish_request(); | ||
} | ||
Varien_Profiler::stop('mage::app::dispatch::send_response'); | ||
Mage::dispatchEvent('controller_front_send_response_after', array('front'=>$this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should go after line 186 in case for some reason someone wants to inject some additional content like an html comment with cache debug info or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @colinmollenhour about moving the location. I also don't see the value is the true ===
bit, it just makes it harder to read.
@Flyingmana Yes, // Flush response before doing post-request processing
flush();
if (isset($_SESSION)) session_write_close();
if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); Wherever it goes just want to make sure it is after any events where a user might want to do some session modifications still. |
I am not sure if this is right to echo stuff later. We use it in Production on this position for around 5/6 month with varnish and Ajax without any issues. Debug Stuff like Appserver Id we put as header. |
Iam for fastcgi_finish_request before the event, because this event should not output any html anymore, as the closing html tag was already send, also I think there is another event before to attach html. I also would not close the session there, as the events listening afterwards probably need to read from it. And the point I was trying to do was, parallel session writing already can happen, and people should avoid writing to the session anyways. |
Is this documented somewhere? I don't see why it can't be so just pointing out a potential BC breakage. Also, Magento is meant to be HMVC I believe so I think this needs to be moved out to a higher level.. For example: https://github.com/colinmollenhour/Cm_Diehard/blob/master/code/Model/Backend/Local.php#L281
Not sure I'm following you here.. What is "parallel session writing"? // Flush response before doing post-request processing
flush();
if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
if (isset($_SESSION)) session_write_close(); |
I propose putting it after this line so that it is guaranteed to be BC: https://github.com/OpenMage/magento-lts/blob/1.9.2.4/app/Mage.php#L685 |
I looked a bit into the event, what it is used for. And we cant close the session before it. Also we have to expect that people make use of the session for such long processing cases we want to support here. I will explain my point with the session_write a bit. Depending on the used backend and the implementation the Session can be a single "big" dataset. This is written on session_close. If the process still runs, and another one is already started, it has no access to the session changes of the long running process. And if the long running process runs longer then the 2. or even 3. process for this one session, it can happen, that it overwrites their session changes. I just wanted to mention this, I actually dont think we should add something for handling this, as the wished handling of this can depend a lot on the shop and the extensions doing such long running stuff. Some of them may require the session, others not. regarding the fastcgi_finish_request() before or after the event. Is there even a later event which is commonly used for longer running processing? |
Please read again: If the user doesn't want to output more data after the response is sent, calling https://github.com/colinmollenhour/Cm_Diehard/blob/master/code/Model/Backend/Local.php#L281 Maybe I'm the only one that ever did this with Magento, but still there is no harm in moving it up the call stack one frame.. |
// to the client open. | ||
if(php_sapi_name() == 'fpm-fcgi' && true === function_exists('fastcgi_finish_request')){ | ||
fastcgi_finish_request(); | ||
} | ||
Varien_Profiler::stop('mage::app::dispatch::send_response'); | ||
Mage::dispatchEvent('controller_front_send_response_after', array('front'=>$this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @colinmollenhour about moving the location. I also don't see the value is the true ===
bit, it just makes it harder to read.
Pfoe. That was hard to read ;) |
Yes, I think it is a good improvement, just belongs in a different location. |
There are situations when the client doesn't wait for server response or resets the connection (e.g. bots). In this case Apache/Nginx error logs will fill up with lines like this one:
Many system administrators trying to find a solution start to adjust FCGI parameters in Apache or PHP configuration files but this doesn't solve the issue. Also it is not coming from a slow script in Magento as a few stated in Forums. If they will check the access logs they will understand only a few IP's generate this issue from time to time those IP's which are banned for SPAM or running bots. As I understand this commit comes to solve an issue like this in Magento. If it works without generating any trouble indeed it is an improvement. |
…mpleted rendering. Add core_app_run_after to allow events to occur after response is sent. Refs OpenMage#113
what would the location be now? so that we could modify the PR and move it forward ;-) |
This PR needs to be rebased to OpenMage:1.9.4.x. |
I would close this PR in favor of #1592. Let's see some 2 - 3 opinions too. @colinmollenhour - what do you think about? |
I vote for 1592. |
Implemented fastcgi_finish_request() to send response to the client as early as possible.
This function flushes all response data to the client and finishes the request. This allows for time consuming tasks to be performed without leaving the connection to the client open.