Node echo server degrades 10x when stream pipes are used over buffering

That’s a funny question you have! In fact, buffered vs piped is not the question here. You have a small chunk; it is processed in one event. To show the issue at hand, you can write your handler like this: let chunk; req.on(‘data’, (dt) => { chunk=dt }); req.on(‘end’, () => { res.write(chunk); res.end(); }); … Read more

What is output buffering in PHP?

Output Buffering for Web Developers, a Beginner’s Guide: Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script. With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script. Advantages of output … Read more

How to clear previously echoed items in PHP

<?php ob_start(); echo ‘a’; print ‘b’; // some statement that removes all printed/echoed items ob_end_clean(); echo ‘c’; // the final output is equal to ‘c’, not ‘abc’ ?> Output buffering functions The output buffering functions are also useful in hackery to coerce functions that only print to return strings, ie. <?php ob_start(); var_dump($myVar); $data = … Read more

PHP buffer ob_flush() vs. flush()

ob_flush sends an application-initiated buffer. There may be multiple nested ob_start()‘s in any PHP script. ob_flush passes the current content to the upper layer. PHP itself might (at its own discretion) buffer output. This depends on the back-end. But usually FastCGI has a socket buffer on its own. Therefore flush() needs to be invoked as … Read more

Test PHP headers with PHPUnit

The issue is that PHPUnit will print a header to the screen and at that point you can’t add more headers. The work around is to run the test in an isolated process. Here is an example <?php class FooTest extends PHPUnit_Framework_TestCase { /** * @runInSeparateProcess */ public function testBar() { header(‘Location : http://foo.com’); } … Read more

What exactly is file.flush() doing?

There’s typically two levels of buffering involved: Internal buffers Operating system buffers The internal buffers are buffers created by the runtime/library/language that you’re programming against and is meant to speed things up by avoiding system calls for every write. Instead, when you write to a file object, you write into its buffer, and whenever the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)