Avatar of DoubleDutch2
DoubleDutch2

asked on 

file_get_contents XML request from PHP takes 12 seconds. Same request from Java takes 1 second..

We run a simple Apacha / PHP server on CentOS 5.0. One of the PHP scripts I use calls a (PHP) XML Webservice using this call:

echo "<br>Before Encode" . date("H:i:s");
$request = xmlrpc_encode_request($WebService, $InputFieldList, $XMLOptions);
echo "<br>Before Stream Context" . date("H:i:s");
$context = stream_context_create(array('http' => array(
'method' => "POST",
      'header' => "Content-Type: text/xml",
      'content' => $request)));
echo "<br>Before Get Content" . date("H:i:s");
$XMLReply       = file_get_contents($ComplateURL , false, $context);
echo "<br>Before Decode" . date("H:i:s");
$DecodedXMLReply       =       xmlrpc_decode($XMLReply);
echo "<br>Done" . date("H:i:s");

When this page is diplayed, the difference between the lines "Befor Get Content" - "Before Decode" takes 12 seconds....

If I call exactly the same XML call using a Java Application the same call, to the same server takes < 1 second. I've tried using CURL instead and that makes no difference.

Any suggestions would be very much appreciated.
PHPApache Web Server

Avatar of undefined
Last Comment
giltjr
Avatar of DoubleDutch2
DoubleDutch2

ASKER

I found a solution but I don't understand why.... The URL I'm trying to get is on the same server. I tried reading the URL with the IP address and suddenly the speed was fine. I then added the domain in question to the local host name and it all worked. I don't understand why though and would appreciate a view on that given that I run a caching DNS server on this box so I guess it must be able to figure out who it is!
ASKER CERTIFIED SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of DoubleDutch2
DoubleDutch2

ASKER

"Java": Yes they are running on the same box and we use the same Domain name! Confused from UK....
SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo