ob_flush需要很长时间才能执行

时间:2022-10-19 18:51:37

In my website(running with drupal) the ob_flush function takes a long time(between 10 - 100 secs) to be executed. How do I find out why? What can cause this so long time? ob_flush需要很长时间才能执行

在我的网站(使用drupal运行)中,ob_flush函数需要很长时间(在10到100秒之间)才能执行。我怎么找出原因?什么能导致这么长时间?

4 个解决方案

#1


2  

Try this:

尝试这个:

ob_start();
//Your code to generate the output
$result = ob_get_contents(); //save the contents of output buffer to a string
ob_end_clean();
echo $result;

It is run quick for me.

它对我来说很快。

#2


0  

use

使用

<?ob_start();?>

at the beginning of the page and

在页面的开头和

 <?ob_flush();?>

at the end of the page, to solve this problem.

在页面的最后,解决这个问题。

#3


0  

SET

output_buffering = Off

output_buffering =关闭

in php.ini

在php.ini中

#4


0  

[You may want to tag your question with Drupal, since this feels like it might be a Drupal issue. Specifically, I suspect that when you flush the buffer, you're writing to an outer buffer, which triggers a ton of hooks to be called to filter the data you've just written.]

[你可能想用Drupal标记你的问题,因为这感觉它可能是一个Drupal问题。具体来说,我怀疑当你刷新缓冲区时,你正在写一个外部缓冲区,它会触发大量的钩子来调用你过去刚才写的数据。

I suspect that your problem is nested buffers. Drupal really likes buffers and buffers everything all over the place. Check the result of:

我怀疑你的问题是嵌套缓冲区。 Drupal非常喜欢缓冲区并缓存所有地方的所有东西。检查结果:

echo "<pre>\nBuffering level: ";
    . ob_get_level() .
    . "\nBuffer status:\n"
    . var_dump(ob_get_status(TRUE))
    . "\n</pre>";

If you've got nested buffers, then I suspect ob_flush() will do nothing for you: it just appends the contents of your inner buffer into the next outermost layer of buffering.

如果你有嵌套缓冲区,那么我怀疑ob_flush()将不会为你做任何事情:它只是将你的内部缓冲区的内容附加到下一个最外层的缓冲区。

Nested buffers can come from Drupal itself (which the above will show), or from the settings for zlib-output-compression and output_buffering (try twiddling those, see if it changes anything).

嵌套缓冲区可以来自Drupal本身(上面将显示),或者来自zlib-output-compression和output_buffering的设置(尝试修改它们,看它是否改变了什么)。

If your buffers are not nested, and the above settings do not help, then you may also want to split the operation into pieces, and run the profiler there, to see which part is taking the time:

如果您的缓冲区没有嵌套,并且上述设置没有帮助,那么您可能还希望将操作拆分为多个部分,并在那里运行探查器,以查看哪个部分占用了时间:

$data = ob_get_contents(); // Return the contents of the output buffer.
ob_clean(); // Clean (erase) the output buffer.
ob_end(); // Close the buffer.
echo($data); // Output our data - only works if there's no outer buffer!
ob_start(); // Start our buffer again.

The question then becomes, though, "what are you trying to accomplish?" What do you think ob_flush() is doing here? Because if the answer is "I want to push everything I've done so far to the browser"... then I'm afraid that ob_flush() just isn't the right way.

然而,问题变成了“你想要完成什么?”您认为ob_flush()在这里做什么?因为如果答案是“我想把我迄今为止所做的一切都推到浏览器上”......那么我担心ob_flush()不是正确的方法。

#1


2  

Try this:

尝试这个:

ob_start();
//Your code to generate the output
$result = ob_get_contents(); //save the contents of output buffer to a string
ob_end_clean();
echo $result;

It is run quick for me.

它对我来说很快。

#2


0  

use

使用

<?ob_start();?>

at the beginning of the page and

在页面的开头和

 <?ob_flush();?>

at the end of the page, to solve this problem.

在页面的最后,解决这个问题。

#3


0  

SET

output_buffering = Off

output_buffering =关闭

in php.ini

在php.ini中

#4


0  

[You may want to tag your question with Drupal, since this feels like it might be a Drupal issue. Specifically, I suspect that when you flush the buffer, you're writing to an outer buffer, which triggers a ton of hooks to be called to filter the data you've just written.]

[你可能想用Drupal标记你的问题,因为这感觉它可能是一个Drupal问题。具体来说,我怀疑当你刷新缓冲区时,你正在写一个外部缓冲区,它会触发大量的钩子来调用你过去刚才写的数据。

I suspect that your problem is nested buffers. Drupal really likes buffers and buffers everything all over the place. Check the result of:

我怀疑你的问题是嵌套缓冲区。 Drupal非常喜欢缓冲区并缓存所有地方的所有东西。检查结果:

echo "<pre>\nBuffering level: ";
    . ob_get_level() .
    . "\nBuffer status:\n"
    . var_dump(ob_get_status(TRUE))
    . "\n</pre>";

If you've got nested buffers, then I suspect ob_flush() will do nothing for you: it just appends the contents of your inner buffer into the next outermost layer of buffering.

如果你有嵌套缓冲区,那么我怀疑ob_flush()将不会为你做任何事情:它只是将你的内部缓冲区的内容附加到下一个最外层的缓冲区。

Nested buffers can come from Drupal itself (which the above will show), or from the settings for zlib-output-compression and output_buffering (try twiddling those, see if it changes anything).

嵌套缓冲区可以来自Drupal本身(上面将显示),或者来自zlib-output-compression和output_buffering的设置(尝试修改它们,看它是否改变了什么)。

If your buffers are not nested, and the above settings do not help, then you may also want to split the operation into pieces, and run the profiler there, to see which part is taking the time:

如果您的缓冲区没有嵌套,并且上述设置没有帮助,那么您可能还希望将操作拆分为多个部分,并在那里运行探查器,以查看哪个部分占用了时间:

$data = ob_get_contents(); // Return the contents of the output buffer.
ob_clean(); // Clean (erase) the output buffer.
ob_end(); // Close the buffer.
echo($data); // Output our data - only works if there's no outer buffer!
ob_start(); // Start our buffer again.

The question then becomes, though, "what are you trying to accomplish?" What do you think ob_flush() is doing here? Because if the answer is "I want to push everything I've done so far to the browser"... then I'm afraid that ob_flush() just isn't the right way.

然而,问题变成了“你想要完成什么?”您认为ob_flush()在这里做什么?因为如果答案是“我想把我迄今为止所做的一切都推到浏览器上”......那么我担心ob_flush()不是正确的方法。