You can set the maximum buffer size in your PHP configuration file. The default is 4096 characters. Below is an extract from a PHP configuration file, showing the default setting: ; - log_errors = On [Security] ; This directive complements the above one. Any errors that occur during the ; execution of your script will be logged (typically, to your server's error log, ; but can be configured in several ways). Along with setting display_errors to off, ; this setup gives you the ability to fully understand what may have gone wrong, ; without exposing any sensitive information to remote users. ; - output_buffering = 4096 [Performance] ; Set a 4KB output buffer. Enabling output buffering typically results in less ; writes, and sometimes less packets sent on the wire, which can often lead to ; better performance. The gain this directive actually yields greatly depends ; on which Web server you're working with, and what kind of scripts you're using. You can send compressed output to browsers by starting output control with ob_start('ob_gzhandler’), minimizing the download size of your pages. The ob_gzhandler() function determines the appropriate type of compression to use (gzip,deflate, or none) based on what the browser can accept. Compression is beneficial only on larger web pages, and in order to use it, the output_buffering setting in thephp.inifile must be set tooff. The ob_get_length() function returns the length of the current buffer contents. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php ob_start(); echo "Go for it "; $oblength1 = ob_get_length(); echo "World"; $oblength2= ob_get_length(); ob_end_clean(); echo $oblength1 . ", ." . $oblength2; var_dump($oblength1, $oblength2); ?> </body> </html> The above code outputs the following: 10, .15 int(10) int(15) The ob_get_contents() function returns the current buffer so that it can be assigned to a variable if needed: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php ob_start(); echo "My name is David Web "; $obcontents1 = ob_get_contents(); echo "and i'm very tired right now"; $obcontents2 = ob_get_contents(); ob_end_clean(); var_dump($obcontents1, $obcontents2); ?> </body> </html> The code above outputs: string(21) "My name is David Web " string(49) "My name is David Web and i'm very tired right now" PHP automatically runs the ob_end_flush() function at the end of a script if it is not otherwise called. But it is better to get into the habit of calling it yourself.
blog comments powered by Disqus |
|
|
|
|
|
|
|