3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Demonstration of a PHP bug: Capturing output as a string with an output buffer stops working * as soon as PHP has detected a client disconnect. * * Verified with different PHP 5.4 and 5.5 builds on Linux and Win7 with Apache 2.2, Apache 2.4 * and PHP-FPM SAPIs. * * PHP-FPM note: When testing with PHP-FPM, make sure the web server does not buffer the reponse. * For nginx, set "gzip off;" and "fastcgi_buffering off;" (only supported by version 1.6 and * above) in the vhost configuration. */ // We record the results in this file after the client connection was closed define('LOG_FILE', __DIR__ . '/ob-bug-test' . PHP_VERSION . '.log'); ini_set('error_log', __DIR__ . '/error.log'); // Let's not bother with HTML... header('Content-Type: text/plain; charset=utf-8'); // Prevent script from exiting when client disconnects ignore_user_abort(true); // Flush & close all output buffers to make the echo/flush calls // below send data to the client immediately while (ob_get_level()) { ob_end_flush(); } // Init log file echo "Results will go to " . LOG_FILE . "\n"; log_message("\n" . date('# Y-m-d H:i:s')); // Run the tests once before the client disconnects test_echo_output_buffer_capturing(); test_gd_output_buffer_capturing(); // Wait until client has closed connection while (!connection_aborted()) { log_message("\nClient is still connected"); // PHP only detects a client disconnect when trying to actually // send rsponse data to the client echo "Abort the request in your browser now by pressing " . "<Esc> or clicking the little X in the adress bar...\n"; flush(); sleep(1); } log_message("\nClient is now disconnected (connection_aborted() returns true)"); // Run the tests again, after client has disconnected test_echo_output_buffer_capturing(); test_gd_output_buffer_capturing(); // ============================================================================= /** * This is what e.g. the popular template engine Twig does when rendering a template. * * A common case when this might happen after client diconnect: when Twig is used to * render the body of an e-mail at the end of a long-running request. */ function test_echo_output_buffer_capturing() { ob_start(); echo 'Hello World'; $captured_output = ob_get_clean(); log_message("\nCapture echo in output buffer:"); log_message(' - captured string length: ' . strlen($captured_output)); } /** * The GD image output functions can either write to a file or to stdout. * * When the binary image data is needed as a string to e.g. write it to a DB blob field, * using an output buffer is a shorter and faster method than writing to a temp file. */ function test_gd_output_buffer_capturing() { // $img = imagecreatetruecolor(100, 100); // ob_start(); // // second imagejpeg() arg === null means "send image data to client/stdout" // // Really strange behaviour: when the client connection is closed, imagejpeg() // // triggers a warning (unrecoverable error) but returns true!? // $success = imagejpeg($img, null, 100); // $captured_output = ob_get_clean(); // imagedestroy($img); // log_message("\nCapture binary image data in output buffer:"); // log_message(' - image data length: ' . strlen($captured_output)); // log_message(' - imagejpeg() return value: ' . ($success ? 'true' : 'false')); } function log_message( $message ) { if (false === file_put_contents(LOG_FILE, $message . "\n", FILE_APPEND)) { die("Sorry, it seems " . LOG_FILE . " is not writable. Aborting...\n"); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0140.00316.88
8.3.50.0080.01021.99
8.3.40.0090.00619.01
8.3.30.0120.00318.92
8.3.20.0030.00620.34
8.3.10.0080.00023.48
8.3.00.0120.00319.51
8.2.180.0040.01216.50
8.2.170.0070.00722.96
8.2.160.0090.00620.35
8.2.150.0050.00324.18
8.2.140.0060.00324.66
8.2.130.0080.00017.63
8.2.120.0040.00426.35
8.2.110.0060.00320.52
8.2.100.0040.00718.05
8.2.90.0050.00519.34
8.2.80.0030.00517.97
8.2.70.0000.01017.75
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0000.00821.25
8.2.30.0000.00820.57
8.2.20.0080.00317.88
8.2.10.0000.00818.14
8.2.00.0000.00718.13
8.1.280.0030.01725.92
8.1.270.0090.00023.96
8.1.260.0030.00528.09
8.1.250.0080.00028.09
8.1.240.0040.00723.83
8.1.230.0000.01217.77
8.1.220.0000.00817.78
8.1.210.0030.00618.77
8.1.200.0060.00317.48
8.1.190.0000.00917.64
8.1.180.0050.00318.10
8.1.170.0030.00718.59
8.1.160.0000.00722.04
8.1.150.0050.00318.88
8.1.140.0050.00319.54
8.1.130.0040.00417.78
8.1.120.0040.00417.55
8.1.110.0040.00417.44
8.1.100.0050.00217.53
8.1.90.0050.00317.45
8.1.80.0050.00217.58
8.1.70.0000.00717.54
8.1.60.0040.00417.62
8.1.50.0030.00617.54
8.1.40.0040.00417.38
8.1.30.0030.00517.59
8.1.20.0030.00517.66
8.1.10.0040.00417.54
8.1.00.0050.00317.54
8.0.300.0050.00218.77
8.0.290.0000.00716.88
8.0.280.0070.00018.47
8.0.270.0000.00817.34
8.0.260.0040.00417.23
8.0.250.0070.00017.07
8.0.240.0000.00817.12
8.0.230.0040.00417.01
8.0.220.0070.00017.05
8.0.210.0030.00517.02
8.0.200.0030.00316.94
8.0.190.0030.00716.92
8.0.180.0070.00016.97
8.0.170.0050.00316.94
8.0.160.0030.00516.90
8.0.150.0040.00417.00
8.0.140.0040.00416.91
8.0.130.0060.00013.30
8.0.120.0040.00417.00
8.0.110.0040.00416.99
8.0.100.0040.00417.05
8.0.90.0070.00016.90
8.0.80.0060.00916.91
8.0.70.0040.00416.80
8.0.60.0000.00717.05
8.0.50.0040.00416.83
8.0.30.0110.00617.22
8.0.20.0130.01217.40
8.0.10.0070.00017.00
8.0.00.0030.01416.94
7.4.330.0030.00316.71
7.4.320.0000.00716.64
7.4.300.0050.00216.44
7.4.290.0050.00316.64
7.4.280.0030.00616.66
7.4.270.0030.00316.50
7.4.260.0000.00716.42
7.4.250.0000.00716.39
7.4.240.0000.00716.54
7.4.230.0070.00016.68
7.4.220.0090.01016.63
7.4.210.0110.00316.60
7.4.200.0000.00816.73
7.4.160.0070.01416.65
7.4.150.0200.00017.40
7.4.140.0080.01017.86
7.4.130.0120.00916.67
7.4.120.0150.00216.64
7.4.110.0070.01116.56
7.4.100.0120.00916.59
7.4.90.0090.00916.80
7.4.80.0090.01219.39
7.4.70.0070.01016.93
7.4.60.0070.01016.53
7.4.50.0100.00616.64
7.4.40.0100.00616.61
7.4.30.0090.00916.70
7.4.10.0070.01015.33
7.4.00.0080.00715.01
7.3.330.0060.00013.41
7.3.320.0000.00513.43
7.3.310.0080.00016.46
7.3.300.0000.00716.48
7.3.290.0060.00816.48
7.3.280.0090.00916.47
7.3.270.0060.01217.40
7.3.260.0070.01016.66
7.3.250.0090.01016.56
7.3.240.0120.00716.56
7.3.230.0120.00616.64
7.3.210.0040.01416.59
7.3.200.0060.00916.68
7.3.190.0060.01116.60
7.3.180.0070.01016.58
7.3.170.0040.01216.52
7.3.160.0100.00716.47
7.3.130.0060.01214.96
7.3.120.0070.01114.97
7.3.110.0060.01214.80
7.3.100.0110.00714.80
7.3.90.0090.00614.94
7.3.80.0090.00315.15
7.3.70.0080.00815.10
7.3.60.0060.00615.02
7.3.50.0100.00614.89
7.3.40.0070.01315.09
7.3.30.0000.01614.99
7.3.20.0030.01016.81
7.3.10.0090.00516.54
7.3.00.0110.00516.37
7.2.330.0130.00316.54
7.2.320.0000.01616.91
7.2.310.0100.00616.94
7.2.300.0220.00016.60
7.2.290.0120.00916.67
7.2.260.0070.01115.12
7.2.250.0090.00915.13
7.2.240.0090.00614.96
7.2.230.0030.01214.81
7.2.220.0090.00915.05
7.2.210.0090.00915.39
7.2.200.0030.01315.18
7.2.190.0030.01015.04
7.2.180.0100.00715.11
7.2.170.0070.00715.04
7.2.160.0030.01715.13
7.2.150.0080.00417.11
7.2.140.0060.00616.94
7.2.130.0080.01016.89
7.2.120.0140.00617.10
7.2.110.0070.00716.61
7.2.100.0080.00816.70
7.2.90.0070.01116.74
7.2.80.0080.00916.88
7.2.70.0090.01016.76
7.2.60.0120.00616.83
7.2.50.0060.00816.91
7.2.40.0120.00716.89
7.2.30.0110.00317.01
7.2.20.0100.01016.87
7.2.10.0080.00816.66
7.2.00.0080.00817.50
7.1.330.0030.00615.46
7.1.320.0090.00915.77
7.1.310.0040.01216.19
7.1.300.0000.01115.90
7.1.290.0100.00015.80
7.1.280.0120.00315.93
7.1.270.0030.01015.61
7.1.260.0030.01015.63
7.1.250.0100.00615.60
7.1.240.0030.01016.05
7.1.230.0040.01116.04
7.1.220.0000.01015.57
7.1.210.0080.00416.03
7.1.200.0080.00415.87
7.1.190.0040.01215.83
7.1.180.0070.00715.56
7.1.170.0100.00715.77
7.1.160.0070.00715.96
7.1.150.0030.01215.72
7.1.140.0110.00715.62
7.1.130.0120.00615.89
7.1.120.0070.00715.70
7.1.110.0070.00415.82
7.1.100.0070.00616.82
7.1.90.0090.00015.62
7.1.80.0030.00715.72
7.1.70.0020.00816.32
7.1.60.0050.01517.68
7.1.50.0040.00716.28
7.1.40.0060.00915.86
7.1.30.0040.00815.52
7.1.20.0040.00815.68
7.1.10.0070.01015.86
7.1.00.0030.03719.04
7.0.330.0090.00615.53
7.0.320.0060.00915.47
7.0.310.0060.00315.73
7.0.300.0070.00715.41
7.0.290.0070.00715.50
7.0.280.0110.00715.47
7.0.270.0080.00815.65
7.0.260.0070.01015.27
7.0.250.0130.00315.62
7.0.240.0090.00615.42
7.0.230.0030.00915.38
7.0.220.0030.00915.51
7.0.210.0030.00915.66
7.0.200.0040.00716.13
7.0.190.0090.00615.69
7.0.180.0000.00815.50
7.0.170.0050.00315.66
7.0.160.0030.00915.62
7.0.150.0090.00615.61
7.0.140.0040.00815.43
7.0.130.0030.00515.55
7.0.120.0070.00715.55
7.0.110.0000.01315.38
7.0.100.0000.01115.44
7.0.90.0070.01015.65
7.0.80.0160.03117.70
7.0.70.0130.02317.86
7.0.60.0180.02417.77
7.0.50.0170.02917.91
7.0.40.0030.05216.89
7.0.30.0080.04116.95
7.0.20.0030.04316.77
7.0.10.0080.02516.87
7.0.00.0080.02516.77
5.6.400.0060.00914.55
5.6.390.0070.01014.55
5.6.380.0030.01014.51
5.6.370.0070.00314.25
5.6.360.0060.01014.53
5.6.350.0070.00714.17
5.6.340.0050.00814.16
5.6.330.0090.00914.36
5.6.320.0040.01214.22
5.6.310.0120.00014.32
5.6.300.0030.00914.50
5.6.290.0060.00314.52
5.6.280.0030.04317.85
5.6.270.0030.01014.41
5.6.260.0030.00614.59
5.6.250.0070.01014.45
5.6.240.0100.00714.53
5.6.230.0030.05017.52
5.6.220.0050.02917.64
5.6.210.0050.02617.55
5.6.200.0090.02717.75
5.6.190.0060.02217.64
5.6.180.0110.04017.84
5.6.170.0150.04217.76
5.6.160.0040.02717.53
5.6.150.0030.03017.66
5.6.140.0070.02317.68
5.6.130.0060.02317.64
5.6.120.0080.02017.79
5.6.110.0070.02317.89
5.6.100.0090.02917.78
5.6.90.0050.02817.84
5.6.80.0070.02317.45
5.6.70.0020.02717.28
5.6.60.0070.01717.28
5.6.50.0070.02217.47
5.6.40.0050.02317.40
5.6.30.0100.01817.42
5.6.20.0080.02217.38
5.6.10.0000.03817.45
5.6.00.0100.02217.25
5.5.380.0120.00614.23
5.5.370.0060.04417.24
5.5.360.0030.02817.32
5.5.350.0060.02317.48
5.5.340.0050.02517.69
5.5.330.0050.02317.52
5.5.320.0070.05117.41
5.5.310.0070.04717.78
5.5.300.0080.03417.65
5.5.290.0060.02117.61
5.5.280.0080.02217.43
5.5.270.0070.02217.51
5.5.260.0070.02217.46
5.5.250.0080.02017.49
5.5.240.0050.02517.10
5.5.230.0080.02117.33
5.5.220.0030.02717.35
5.5.210.0030.02317.21
5.5.200.0050.02417.13
5.5.190.0020.02517.20
5.5.180.0040.03917.33
5.5.170.0090.00613.89
5.5.160.0030.02517.22
5.5.150.0030.02817.29
5.5.140.0050.02717.26
5.5.130.0030.03117.28
5.5.120.0010.02317.33
5.5.110.0030.02517.25
5.5.100.0080.02817.28
5.5.90.0050.04316.99
5.5.80.0080.02817.17
5.5.70.0030.03317.17
5.5.60.0080.04316.89
5.5.50.0050.04517.16
5.5.40.0070.03717.03
5.5.30.0070.04217.26
5.5.20.0110.03817.24
5.5.10.0050.04817.29
5.5.00.0070.04017.22

preferences:
47.9 ms | 401 KiB | 5 Q