计算触发的文件请求数

发布于 2024-10-06 08:06:14 字数 299 浏览 5 评论 0原文

是否可以在 apache debian Web 服务器上使用 PHP(5) 或其他 Linux 工具来获取单个 http 请求的文件请求? 出于性能原因,我想将它们与我的蛋糕应用程序的缓存“版本”进行比较。

在某些视图中,非缓存的数量可能超过 100。 最多只缓存 10 个(希望如此)。

afaik 有 3 个主要文件功能: file_get_contents()、file() 和手动 fopen() 等,

但我无法覆盖它们,因此我无法在其中放置 logRequest() 函数。 还有其他办法吗?将回调附加到函数?拦截文件请求?

Is it possible with PHP(5) or other Linux tools on an apache debian webserver to get the file requests a single http request made?
for performance reasons i would like to compare them with the cached "version" of my cake app.

non-cached that might be over 100 in some views.
cached only up to 10 (hopefully).

afaik there are 3 main file functions:
file_get_contents(), file() and the manual fopen() etc

but i cannot override them so i cannot place a logRequest() function in them.
is there any other way? attaching callbacks to functions? intercepting the file requests?

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

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

发布评论

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

评论(5

何止钟意 2024-10-13 08:06:14

你可以看看 xdebug - function trace

这个建议似乎并不直观,但是一旦你有了 xdebug, 安装并启用后,您可以使用各种配置将分析保存到磁盘文件中,并可以稍后检索它。例如不同 URL 的分析结果保存到不同的磁盘文件中。

要监视文件系统相关功能,您可以对文本文件进行解析(分析结果)并计算可匹配的功能(可编程或手动)

This suggestion does not seems intuitive, but you can take look on xdebug - function trace

Once you have xdebug installed and enabled, you can using all sort of configuration to save the profiling into a disk file and you can retrieve it later. Such as profiling results for different URL save into different disk file.

To monitoring file system related functions, you can do a parse of the text file(profiling results) and do a count of matchable functions (programmable or manually)

厌倦 2024-10-13 08:06:14

我的方法是创建一个自定义函数来包装您需要的函数。

function custom_file_get_contents($filename) {
    $GLOBALS['file_get_contents_count']++;
    return file_get_contents($filename);
}

只需将所有对 file_get_contents 的调用替换为 custom_file_get_contents 即可。这只是一个基本的例子,但你已经明白了。

旁注,如果您想计算脚本已包含(或需要)的文件数量,请参阅 get_included_files()

The way I would do it would be to create a custom function that wraps around the one you need.

function custom_file_get_contents($filename) {
    $GLOBALS['file_get_contents_count']++;
    return file_get_contents($filename);
}

And just replace all of your calls to file_get_contents with custom_file_get_contents. This is just a rudimentary example, but you get the idea.

Side note, if you want to count how many files your script has included (or required), see get_included_files()

若能看破又如何 2024-10-13 08:06:14

您可以使用 Xdebug 记录所有函数调用

当您刚接触应用程序或试图弄清楚应用程序运行时到底发生了什么时,这些所谓的“函数跟踪”可能会有所帮助。函数跟踪还可以选择显示传递给函数和方法的变量值以及返回值。在默认跟踪中,这两个元素不可用。

You can use Xdebug to log all function calls

Those so-called "function traces" can be a help for when you are new to an application or when you are trying to figure out what exactly is going on when your application is running. The function traces can optionally also show the values of variables passed to the functions and methods, and also return values. In the default traces those two elements are not available.

撩发小公举 2024-10-13 08:06:14

有趣的问题。我将从 stream_wrapper 开始......尝试用自定义类替换它们。

Interesting question. I'd start with the stream_wrapper ... try to replace them with custom classes.

有一个名为 ADB(高级 PHP 调试器)的 pecl 扩展,它有两个对于这样的 cse 非常有用的函数 - override_function() 和 rename_function()。你可以这样做:

rename_function('file_get_contents', 'file_get_contents_orig');

function file_get_contents($filename) {
    logRequest();
    return file_get_contents_orig($filename);
}

看起来 ADB 也很容易安装。

请参阅http://www.php.net/manual/en/book.apd。 php

There is a pecl extention called ADB (Advanced PHP Debugger) that has tow functions that would be very useful for a cse like this - override_function() and rename_function(). You could do something like this:

rename_function('file_get_contents', 'file_get_contents_orig');

function file_get_contents($filename) {
    logRequest();
    return file_get_contents_orig($filename);
}

It looks like ADB is pretty easy to install, too.

See http://www.php.net/manual/en/book.apd.php

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