I am using Apache. How do I fork a web services request so that the two app servers can receive the same request? Do not worry about having too many return response, because one of the two App Server will not reply anything. I have no control over who calls the web service, meaning SSI pages are out. Can it be done through Apache configuration rather than writing custom handlers?
views:
147answers:
3One approach would be to write a third proxy application which services the requests, and performs two internal requests to the other two applications, returning whichever result is desired.
Alternatively, with mod_perl (or a regular module written in C) you could also install a PerlAccessHandler which could intercept requests, make a subrequest to the first app before letting execution continue into the second app.
Here's a rough example of how you'd put that together
package MyApache2::MyProxy;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::Const -compile => qw(FORBIDDEN OK);
sub handler {
my $r = shift;
#prepare a user agent to make the request
my $ua = LWP::UserAgent->new;
$ua->agent("MyUserAgent/0.1");
#make a request on the app1 domain with the same uri
$app1url="http://app1.domain".$r->unparsed_uri();
my $request = HTTP::Request->new(GET => $app1url);
my $response = $ua->request($request);
#check the outcome of the response
if ($response->is_success)
{
#check $response->content if you like
}
#tell apache it's ok to continue, falling through to app 2
return Apache2::Const::OK;
}
1;
Now your app2 vhost can use the handler by doing something like this in its configuration
<Location />
PerlAccessHandler MyApache2::MyProxy
</Location>
Another (a bit "dirty") trick would be auto prepend php script to first webapp in which you launch second app. The downside of this approach is that you will have to wait 2° app to terminate before the first app is started. So it depends on complexity and speed of your applications.
.Htaccess code
php_value auto_prepend_file "learn.php"
You might create SSI page, that'll handle that.
index.shtml
<!--#include virtual="/path/to/app1/index.php?$QUERY_STRING -->
<!--#include virtual="/path/to/app2/index.py?$QUERY_STRING -->
http://httpd.apache.org/docs/2.2/mod/mod_include.html#includevirtual