skip to Main Content

I am working on a high traffic site that parses an XML file to display pages to users. I’m going thru the process of optimizing existing code as much as possible, gzip, cache control, etc etc. I think I may putting unnecessary stress on the server with simplexml_load_file.

The users load a page on the the domain (http://xml.domain.com/) and XML is retrieved from a subdomain (http://xml.domain.com/) on the same physical server. I currently use simplexml_load_file and the resulting $info lets me pull the specific needed output like so:

$url = "http://xml.domain.com/directory/file.xml";
$info = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);

Now, the question is, if these XML files are on the same physical server, is it possible to not make these calls over http? I have tried various path changes to no avail:

$url = "/var/www/vhosts/domain.com/subdomains/xml/httpdocs/directory/file.xml";

I’m running Apache/2.2.3 (CentOS), PHP Version 5.2.6, and Plesk 8.6.0. I am hosting with mediatemple – a (dv) server. Thanks.

5

Answers


  1. You can access it if it’s on the same disk. Just make sure that the PHP file has permission to access the XML file. Whatever you do, don’t call it over HTTP; totally unnecessary time consumption.

    Login or Signup to reply.
  2. The path to the xml files depends on your setup. You don’t need to make the call over http. However if your xml file contains PHP code, you’ll need to run it through the PHP interpreter manually.

    If you want to speed up things, you should rethink if you really need to parse this xml file on each request. Depends a bit on your situation again. You could use something like memcached to cache the output for some seconds/minutes/hours and you’ll probably get a better result than with only replacing the http call.

    Login or Signup to reply.
  3. Personally, I’ve siwtched from SimpleXML to DOMDocument.

    you can use

    $xmldoc = new SimpleXMLElement(file_get_contents($file));
    //or 
    $xmldoc = new DOMDocument();
    $xmldoc->loadXML(file_get_contents($file);
    

    Permissions are an issue as well as if you are jail/suexec-ed.

    Login or Signup to reply.
  4. There should be no reason why you shouldn’t be able to use the filesystem path – except maybe for file permissions.

    Login or Signup to reply.
  5. You code should rork fine unless the XML has php in it that needs to be parsed (as svens said). Additionally if you are testing for success make sure you use the strict equality operator === as opposed to ==. That may be your problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search