Question

I run a php script from xampp portable on windows. The script takes over a minute. Recently, the script is having flush() problem, as echo statements are not immediately displayed. The script used to work fine earlier with no buffering problem.

Interestingly, I ran the same script copying the xampp portable to another system and the flush statements were working without any problem. Same code, Same xampp portable.

What could be the reason?

Was it helpful?

Solution 6

I figured out that the problem is with antivirus. I recently switched to Bitdefender from Avast. When I switched back to Avast, the problem disappeared miraculously. So, i guess antivirus is also a factor here.

OTHER TIPS

Make the first line of your script ob_implicit_flush();.

or

Change the php.ini file setting implicit_flush = On.

From the documentation:

implicit_flush boolean, FALSE by default. Changing this to TRUE tells PHP to tell the output layer to flush itself automatically after every output block. This is equivalent to calling the PHP function flush() after each and every call to print or echo and each and every HTML block.

When using PHP within an web environment, turning this option on has serious performance implications and is generally recommended for debugging purposes only.

I read other responses and you keep insisting on the fact that your home environment and your work environment are the same. However, you can see that there is a difference. This point of view really help (at least to me) to investigate problems.

Since you did not provide many details about the problem, I would try the following checklist:

  • Settings
    • Is your PHP settings really identical? Try to compare results of phpinfo() on both environments.
  • Data

    • Do you really test your script on identical data? There are many subtle problems that are described in PHP manual:

      Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the tag of the outermost table is seen.

      Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.

      http://php.net/manual/en/function.flush.php

      or

      http://www.php.net/manual/en/function.ob-flush.php#90529 (commenters point out many problems that you may experience)

    • Try dummy plaintext data instead of HTML. You may try to output simple lines like current time and check behaviour of your script.

  • Browsers

    • Try a few browsers (with cleared cache) to see if the issue is browser-specific or not.

I think it may be your browser. Have you cleaned the temporary settings of Iron Portable browser?

this occurs when you use gzip and there is some output have been send so the browser get confused to solve this , i uses this code always

if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)
    {ob_start('ob_gzhandler'); ob_start();}
else
    ob_start();

You have not mentioned about the versions of windows both the systems running. Are the systems completely identical?

You also said that you are running a portable version of XAMPP , if you are using a pen drive/thump drive there is a chance that data transfer speeds can vary due to USB speeds.

I had a similar issue where the First system had USB legacy ports and the second one I tested has usb 2+ ports or higher.

The speed and processing time changed based on the systems, while one system took 20 seconds , other took nearly 60 seconds to process.

The slow system produced undesired results [I was working on an image processor].

I guess your case is similar and had to do a lot with the system vitals.

Cheers Clain

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top