读取文件与包含文件

发布于 2024-10-16 14:45:39 字数 667 浏览 2 评论 0原文

考虑以下情况:

有一个大型项目,其中包含一个父站点以及多个“子”站点,它们都共享相同的“核心/基础”内容..(图像、“包含”、样式表等)

我 目的是让这些重复文件驻留在一台特定服务器上,并在需要时始终引用相同的路径。

这将导致任何修改的“核心”文件(图像、“包含”、样式表等)影响所有交叉引用。

最好的方法是什么?


目前,(可能暂时)我正在使用以下 ..

这是一种尝试,最接近

这带来了一个明显的问题 - 使用以下内容来定位当前页面将不再起作用。 其次,通过“readfile”检索内容是否不安全?

<?php $url = basename($_SERVER['SCRIPT_FILENAME']); echo $url; ?>

这当然会返回该文件的路径,'top_nav.php'

如何使用类似的方法获取 url / Web 地址的值?

任何见解将不胜感激!干杯。

Consider the following:

I have a large project which consists of a parent site, alongside multiple 'child' sites, to which they all share identical 'core / base' content.. (images, 'includes', stylesheets, etc.)

My intent is to have these recurring files reside on 1 particular server, and always reference the same path when in need.

This would result in any modified 'core' files (images, 'includes', stylesheets, etc.) affecting all cross references.

What's the best way to go about at this?


currently, (possibly temporarily) I'm using the following .. <?php readfile('http://remotepath.com/_core/includes/top_nav.php'); ?>

Which is an attempt, at nearest solution to <?php include('/filepath/'); ?>

This brings up an obvious issue - using the following to target current page, will no longer work..
Secondly, is retrieving the content via 'readfile' insecure?

<?php $url = basename($_SERVER['SCRIPT_FILENAME']); echo $url; ?>

this will of course return the path of that file, 'top_nav.php'

How can I get the value of the url / web address using a similar method?

Any insight would be well appreciated! Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝颜夕 2024-10-23 14:45:39

不要这样做。

将图像、脚本和样式表放在另一台服务器上是可以的。事实上,这实际上是一件好事——这意味着您可以同时下载更多文件,这将加快网站的加载速度。然而,对远程文件进行 include 调用会造成很大的破坏。这是因为这会使您的服务器向远程服务器发出 HTTP 请求。当发生这种情况时(并且很容易需要一秒钟或更长时间),您的脚本将什么也不做。它会极大地减慢您的网站速度。

无论如何,在站点之间共享文件。但是,我强烈建议您在渲染页面时不要这样做。您可能希望定期从父服务器将文件下载到子服务器上,然后通常从本地文件系统包含它们。

注意:您可以通过 HTTP 调用includereadfile这一事实并不意味着您应该

Don't do this.

It is fine to have your images, scripts and stylesheets on another server. Indeed, this is actually a good thing -- it means you can have more simultaneous file downloads, which will speed up the loading of your site. However, it will be very damaging to do include calls on remote files. This is because that makes your server do an HTTP request to the remote server. While this takes place (and it could easily take a second or more) your script will do nothing at all. It will slow down your site enormously.

By all means share files between sites. However, I would strongly urge you not to do so as your pages are rendered. You may wish to periodically download files onto the child servers from the parent server and then include them normally from your local file system.

NB The fact that you can call include or readfile over HTTP does not mean that you should.

旧伤还要旧人安 2024-10-23 14:45:39

不要远程包含源文件。如果您希望在多个不同的服务器上获得相同的 PHP 库副本,可以使用一些简单的方法来实现。您可以 cron 一个 rsync,定期将任何更改从主服务器复制到从服务器,或者将共享文件放入源代码控制系统(如 git)中,然后在每个从服务器上 cron 一个“git pull”命令。

Don't remote include source files. If you want the same copy of a PHP library on a number of different servers, there are a few simple ways to do it. You could cron an rsync that periodically copies any changes from the master to the slaves, or put your shared files into a source code control system like git and then cron a "git pull" command on each slave.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文