Language/Tool versions:
Issue:
I have an Angular2 application which uses a PHP application as an API for all the XHR requests. The application works fine but when the Use a prediction service to load pages more quickly
option is enabled in Chrome, and when the application is reloaded HTTP requests sent inside ngOnInit()
of the component gets stuck for very long. Either the request will resolve itself after 10s-2-3mins, etc or the request(s) will also resolve if I send another request(for example, a request upon a click event on the DOM)
Things I tried:
GET
request and then keeps waiting, upon resolution, there will be a successful OPTIONS
request and then a successful GET
.http://api.randomuser.me/
rather than requesting my API endpoint.
In this case, the request succeeds without any delay(although it
shows CORS errors). So I think the problem resides in either my
backend API or the Apache web server.I would also like to share my virtual host configuration. If you find any problems there:
<VirtualHost *:80>
ServerName someName.api
DocumentRoot path_to_public_dir
SetEnv APPLICATION_ENV development
<Directory path_to_public_dir>
SetEnvIf Origin "http(s)?://(www\.)?(local\.)?(localhost:4200|someDomain.com)$" AccessControlAllowOrigin=$0
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} –d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride none
Order Allow,Deny
Allow from all
</Directory>
Please note:
Access-Control-Allow-Origin
header inside the application itself, but still no luck.Your suggestions/answers on to what all could be the possible causes for such a behavior would be really helpful.
The Network pending state on time, means your request is in progressing state. As soon as it responds the time will be updated with total elapsed time. This picture shows the network call is in processing state(Pending) This picture shows the time taken in processing by network call.
Pending requests are requests that are submitted to the system, but are not yet completed.
Well, I think, doing the following has removed the lag from my machine.
Before the solution, here are my assumptions:
Solution:
I included the mpm
modules file for apache. You can find the
below line in httpd.conf
file:
#Include conf/extra/httpd-mpm.conf
and uncomment it.
Windows uses the mpm_winnt_module for mpm.
This Multi-Processing Module (MPM) is the default for the Windows NT operating systems. It uses a single control process which launches a single child process which in turn creates threads to handle requests
Find the lines below and uncomment them:
EnableMMAP off
EnableSendfile on
AcceptFilter http none
AcceptFilter https none
#Extra Notes
#mmap is memory map by apache, don't know I have uncommented this, had read about
this somewhere, but anyway its Off so should not be a Burden on OS
#EnableSendFile:Delivering static files? This link may help:
https://groups.drupal.org/node/68333
#AcceptFilter: windows mpm module, suggests to keep it as none.
I went through this : https://httpd.apache.org/docs/2.4/mod/core.html
and have set AcceptFilter http/https as "connect", it works fine for me.
Please note: I am using Apache 2.4.23
That's it!
I am leaving this question as unaccepted because:
winnt
module, I couldn't find the module
file anywhere in my apache directory, although changes in the
ThreadsPerChild is reflected, I guess apache doesn't need an
external winnt
module.failed and finshed
requests for every request in my chrome
console.Your answers will be really valuable and make things more clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With