在同一服务器上通过 http 进行 PHP simplexml_load_file 吗?
我正在开发一个高流量站点,该站点解析 XML 文件以向用户显示页面。我将尽可能地优化现有代码、gzip、缓存控制等。我认为我可能会使用 simplexml_load_file 给服务器带来不必要的压力。
用户加载域 (http://xml.domain.com/) 上的页面,并从同一物理服务器上的子域 (http://xml.domain.com/) 检索 XML。我目前使用 simplexml_load_file ,生成的 $info 让我可以像这样提取特定的所需输出:
$url = "http://xml.domain.com/directory/file.xml";
$info = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
现在的问题是,如果这些 XML 文件位于同一台物理服务器上,是否可以不通过 http 进行这些调用?我尝试了各种路径更改但无济于事:
$url = "/var/www/vhosts/domain.com/subdomains/xml/httpdocs/directory/file.xml";
我正在运行 Apache/2.2.3 (CentOS)、PHP 版本 5.2.6 和 Plesk 8.6.0。我正在托管 mediatemple - 一个(dv)服务器。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
xml 文件的路径取决于您的设置。您不需要通过 http 进行调用。但是,如果您的 xml 文件包含 PHP 代码,则需要通过 PHP 解释器手动运行它。
如果你想加快速度,你应该重新考虑是否真的需要在每个请求上解析这个 xml 文件。再次取决于你的情况。您可以使用 memcached 之类的东西将输出缓存几秒/分钟/小时,并且您可能会得到比仅替换 http 调用更好的结果。
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.
如果它位于同一磁盘上,则可以访问它。只需确保 PHP 文件有权访问 XML 文件即可。无论你做什么,都不要通过 HTTP 调用它;完全不必要的时间消耗。
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.
就我个人而言,我已经从 SimpleXML 转向 DOMDocument。
你可以使用
权限以及你是否被监禁/suexec-ed都是一个问题。
Personally, I've siwtched from SimpleXML to DOMDocument.
you can use
Permissions are an issue as well as if you are jail/suexec-ed.
应该没有理由不能使用文件系统路径 - 除了文件权限之外。
There should be no reason why you shouldn't be able to use the filesystem path - except maybe for file permissions.
你的代码应该可以正常工作,除非 XML 中有 php 需要解析(正如 svens 所说)。此外,如果您要测试是否成功,请确保使用严格相等运算符
===
而不是==
。那可能是你的问题。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.