SlideShare una empresa de Scribd logo
1 de 32
Output Buffering Control with  php By Tim LeClair Senior Web Developer, Skills Gatekey Corporation
Who is this presentation for? ,[object Object],[object Object],[object Object],[object Object]
Why use Output Buffers? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Lesson objectives Gains in one can equal loss in another!
Output Control Functions ,[object Object],Initialize  / Functions / Exiting ,[object Object]
Output Control Functions ,[object Object],[object Object],[object Object],[object Object],Initialize / Functions /  Exiting
Output Control Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],Initialize /  Functions  / Exiting
Output Control Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Initialize /  Functions  / Exiting
Compression options ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Remember rule:  compressing twice is a bad thing! This is not a lesson on compression but need to know to prevent conflict.
Gzip and Output Buffers ,[object Object],[object Object],[object Object],[object Object],[object Object]
Zlib extension ,[object Object],[object Object],XAMPP for Linux  The distribution for Linux systems (tested for SuSE, RedHat, Mandrake and Debian) contains: Apache, MySQL, PHP & PEAR, Perl, ProFTPD, phpMyAdmin, OpenSSL, GD, Freetype2, libjpeg, libpng, gdbm ,  zlib , expat, Sablotron, libxml, Ming, Webalizer, pdf class, ncurses, mod_perl, FreeTDS, gettext, mcrypt, mhash, eAccelerator, SQLite and IMAP C-Client.  XAMPP for Windows   The distribution for Windows 98, NT, 2000, 2003, XP and Vista. This version contains: Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, JpGraph, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.  phpinfo();
HTTP compression ,[object Object],Yslow  On Firefox with Firebug SmartSniff  http://www.nirsoft.net Without compression Twitter With compression
Using callback functions  ,[object Object],[object Object],[object Object],[object Object],Getting Started ,[object Object],[object Object],[object Object],[object Object]
Exiting output buffers ,[object Object],Easiest way ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Almost as easy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Buffer Levels Level 1 Level 2 Level 3 Level 4 Server Level 3 Output to Browser Ob_start (ob_gzhandler) Ob_start (condense) Ob_start (ob_tidyhandler) Ob_start 20 Db calls cache.php If (cache.php ) readfile(cache.php) else  Level 4 Tidy it up Remove junk Compression Ob_start (4heckofit) Header Top Right Menu Advertisement Left Ads BLOG Header Top Right Menu Advertisement BLOG Left Ads Bottom Bottom
Project 1a - Output buffering <?php // top of index.php ob_start (); // the rest of your website ob_end_flush (); ?>
Project 2a – Nesting 1452 Answer = <?php ob_start (); echo   &quot;1&quot; ; ob_start (); echo   &quot;2&quot; ; $s1  =  ob_get_contents (); ob_start (); echo   &quot;3&quot; ; $s2  =  ob_get_contents (); ob_end_flush (); ob_end_clean (); echo   &quot;4&quot; ; ob_start (); echo   &quot;5&quot; ; ob_end_flush (); echo   $s1 ; ob_end_flush (); ?>
Project 2b – Nesting 12452 Answer = <?php ob_start (); echo   &quot;1&quot; ; ob_start (); echo   &quot;2&quot; ; $s1  =  ob_get_contents (); ob_flush (); ob_start (); echo   &quot;3&quot; ; $s2  =  ob_get_contents (); ob_end_flush (); ob_end_clean (); echo   &quot;4&quot; ; ob_start (); echo   &quot;5&quot; ; ob_end_flush (); echo   $s1 ; ob_end_flush (); ?>
Project 2c – Nesting 1234523 Answer = <?php ob_start (); echo   &quot;1&quot; ; ob_start (); echo   &quot;2&quot; ; $s1  =  ob_get_contents (); ob_flush (); ob_start (); echo   &quot;3&quot; ; $s2  =  ob_get_contents (); ob_flush (); ob_end_flush (); ob_flush (); ob_end_clean (); echo   &quot;4&quot; ; ob_start (); echo   &quot;5&quot; ; ob_end_flush (); echo   $s1 . $s2 ; ob_flush (); echo   &quot;7&quot; ; ob_end_clean (); ?>
Project 3a – Other functions <?php ob_start (); ob_start (); echo   ob_get_length () . '- length<br>' ; echo   ob_get_level () . '- level<br>' ; echo   ob_get_length () . '- length<br>' ; ob_end_flush (); echo   ob_get_level () . '- level<br>' ; ob_end_flush (); ?> 0- length 2- level 25- length 1- level Level 0 = no buffer
Project 3b – Other functions <?php ob_start (); ob_start (“ ob_tidyhandler ”); echo   '<br>' ; echo   '<br>' ; $s  =  ob_get_status ( true ); print_r ( $s ); ob_end_flush (); ob_end_flush (); ?> Array ( [0] => Array ( [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 1 [status] => 0 [name] => default output handler [del] => 1 )  [1] => Array ( [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 1 [status] => 0 [name] => ob_tidyhandler output handler [del] => 1 ) )
Project 3c – Other functions <?php ob_start ( &quot;ob_gzhandler&quot; ); ob_start ( “condense” ); ob_start ( 'ob_tidyhandler' ); ob_start (); $s  =  ob_list_handlers (); print_r ( $s ); ob_end_flush (); ob_end_flush (); ob_end_flush (); ob_end_flush (); ?> Array ( [0] => ob_gzhandler [1] => ob_tidyhandler [2] => default output handler )
Project 4a – Output to file <?php ob_start ( &quot;ob_gzhandler&quot; ); // dynamic content // check database if page has been modified $cachefile  =  $_SERVER [ 'DOCUMENT_ROOT' ]. &quot;/cache/cache09.php&quot; ; if ( $pagemodified  !=  'Y'  &&  file_exists ( $cachefile )){ readfile ( $cachefile ); } else { // content to be cached $fp  =  fopen ( $cachefile ,  'w' ); fwrite ( $fp ,  ob_get_contents ()); @ chmod ( $fp , 0755 ); ob_end_flush () } // more dynamic content ob_end_flush () ?>
Project 4b – Cache file system <?php $cacheFile  =  'cache.html' ; if  ( ( file_exists ( $cacheFile )) && (( fileatime ( $cacheFile ) +  600 ) >  time ()) ) { $content  =  file_get_contents ( $cacheFile ); echo   $content ; }  else  { ob_start (); // write content echo   'What Ever You Want!' ; $content  =  ob_get_clean (); file_put_contents ( $cacheFile , $content ); echo   $content ; } ?>
Project 5 – rewrite variable <?php output_add_rewrite_var ( 'var' ,  'value' ); echo   '<a href=&quot;file.php&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a>' ; echo   '<form action=&quot;script.php&quot; method=&quot;post&quot;> <input type=&quot;text&quot; name=&quot;var2&quot; /> </form><br>' ; print_r ( ob_list_handlers ()); ob_end_flush (); output_reset_rewrite_vars (); echo   '<br><a href=&quot;file.php&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a>' ; echo   '<form action=&quot;script.php&quot; method=&quot;post&quot;> <input type=&quot;text&quot; name=&quot;var2&quot; /> </form><br>' ; print_r ( ob_list_handlers ()); ?> <a href=&quot;file.php?var=value&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a> <form action=&quot;script.php&quot; method=&quot;post&quot;><input type=&quot;hidden&quot; name=&quot;var&quot; value=&quot;value&quot; />
Project 6 – Less HTML less readable <?php function   condense ( $buffer ){ // change new lines and tabs to single spaces $buffer  =  str_replace ( array ( &quot;&quot; ,  &quot;&quot; ,  &quot;&quot; ,  &quot;&quot; ), ' ' , $buffer ); // multispaces to single... $buffer  =  ereg_replace ( &quot; {2,}&quot; ,  ' ' , $buffer ); // remove single spaces between tags $buffer  =  str_replace ( &quot;> <&quot; ,  &quot;><&quot; ,  $buffer ); // remove single spaces around &nbsp; $buffer  =  str_replace ( &quot; &nbsp;&quot; ,  &quot;&nbsp;&quot; ,  $buffer ); $buffer  =  str_replace ( &quot;&nbsp; &quot; ,  &quot;&nbsp;&quot; ,  $buffer ); return   $buffer ; } ob_start ( &quot;  condense   &quot; ); // your website ob_end_flush (); ?> Can Be Very Costly
Project 7 – Tidyhandler <?php ob_start ( 'ob_tidyhandler' ); echo   '<p>test</i>' ; ?> <!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 3.2//EN&quot;> <html> <head> <title></title> </head> <body> <p> test </p> </body> </html> http://ditio.net/2008/01/03/is-your-html-code-tidy/ Uncomment in php.ini 4 xampp ;extension=php_sybase_ct.dll ;extension=php_threads.dll extension=php_tidy.dll ;extension=php_timezonedb.dll ;extension=php_translit.dll
Project 8 – Compression level <?php ini_set ( 'zlib.output_compression_level' ,  8 ); ob_start ( &quot;ob_gzhandler&quot; ); // html ob_end_flush (); ?>
Bug reports ,[object Object],[object Object],[object Object]
WIMP  issues ,[object Object],This lecture was written with Apache as the example server.  If you are using IIS then it is recommended to look closely at how IIS handles buffers and compression.
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Did lesson meet its intended objectives
Questions Sorry, we do not answer questions  If you come across this document online, please refer to  www.php.net  or use a search engine to find your answers.  Else if you catch me standing in front of you, then I will do my best to answer your questions.
The End ,[object Object],[object Object],[object Object]

Más contenido relacionado

Último

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Destacado

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destacado (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Output Buffering Control with PHP

  • 1. Output Buffering Control with php By Tim LeClair Senior Web Developer, Skills Gatekey Corporation
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Buffer Levels Level 1 Level 2 Level 3 Level 4 Server Level 3 Output to Browser Ob_start (ob_gzhandler) Ob_start (condense) Ob_start (ob_tidyhandler) Ob_start 20 Db calls cache.php If (cache.php ) readfile(cache.php) else Level 4 Tidy it up Remove junk Compression Ob_start (4heckofit) Header Top Right Menu Advertisement Left Ads BLOG Header Top Right Menu Advertisement BLOG Left Ads Bottom Bottom
  • 15. Project 1a - Output buffering <?php // top of index.php ob_start (); // the rest of your website ob_end_flush (); ?>
  • 16. Project 2a – Nesting 1452 Answer = <?php ob_start (); echo &quot;1&quot; ; ob_start (); echo &quot;2&quot; ; $s1 = ob_get_contents (); ob_start (); echo &quot;3&quot; ; $s2 = ob_get_contents (); ob_end_flush (); ob_end_clean (); echo &quot;4&quot; ; ob_start (); echo &quot;5&quot; ; ob_end_flush (); echo $s1 ; ob_end_flush (); ?>
  • 17. Project 2b – Nesting 12452 Answer = <?php ob_start (); echo &quot;1&quot; ; ob_start (); echo &quot;2&quot; ; $s1 = ob_get_contents (); ob_flush (); ob_start (); echo &quot;3&quot; ; $s2 = ob_get_contents (); ob_end_flush (); ob_end_clean (); echo &quot;4&quot; ; ob_start (); echo &quot;5&quot; ; ob_end_flush (); echo $s1 ; ob_end_flush (); ?>
  • 18. Project 2c – Nesting 1234523 Answer = <?php ob_start (); echo &quot;1&quot; ; ob_start (); echo &quot;2&quot; ; $s1 = ob_get_contents (); ob_flush (); ob_start (); echo &quot;3&quot; ; $s2 = ob_get_contents (); ob_flush (); ob_end_flush (); ob_flush (); ob_end_clean (); echo &quot;4&quot; ; ob_start (); echo &quot;5&quot; ; ob_end_flush (); echo $s1 . $s2 ; ob_flush (); echo &quot;7&quot; ; ob_end_clean (); ?>
  • 19. Project 3a – Other functions <?php ob_start (); ob_start (); echo ob_get_length () . '- length<br>' ; echo ob_get_level () . '- level<br>' ; echo ob_get_length () . '- length<br>' ; ob_end_flush (); echo ob_get_level () . '- level<br>' ; ob_end_flush (); ?> 0- length 2- level 25- length 1- level Level 0 = no buffer
  • 20. Project 3b – Other functions <?php ob_start (); ob_start (“ ob_tidyhandler ”); echo '<br>' ; echo '<br>' ; $s = ob_get_status ( true ); print_r ( $s ); ob_end_flush (); ob_end_flush (); ?> Array ( [0] => Array ( [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 1 [status] => 0 [name] => default output handler [del] => 1 ) [1] => Array ( [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 1 [status] => 0 [name] => ob_tidyhandler output handler [del] => 1 ) )
  • 21. Project 3c – Other functions <?php ob_start ( &quot;ob_gzhandler&quot; ); ob_start ( “condense” ); ob_start ( 'ob_tidyhandler' ); ob_start (); $s = ob_list_handlers (); print_r ( $s ); ob_end_flush (); ob_end_flush (); ob_end_flush (); ob_end_flush (); ?> Array ( [0] => ob_gzhandler [1] => ob_tidyhandler [2] => default output handler )
  • 22. Project 4a – Output to file <?php ob_start ( &quot;ob_gzhandler&quot; ); // dynamic content // check database if page has been modified $cachefile = $_SERVER [ 'DOCUMENT_ROOT' ]. &quot;/cache/cache09.php&quot; ; if ( $pagemodified != 'Y' && file_exists ( $cachefile )){ readfile ( $cachefile ); } else { // content to be cached $fp = fopen ( $cachefile , 'w' ); fwrite ( $fp , ob_get_contents ()); @ chmod ( $fp , 0755 ); ob_end_flush () } // more dynamic content ob_end_flush () ?>
  • 23. Project 4b – Cache file system <?php $cacheFile = 'cache.html' ; if ( ( file_exists ( $cacheFile )) && (( fileatime ( $cacheFile ) + 600 ) > time ()) ) { $content = file_get_contents ( $cacheFile ); echo $content ; } else { ob_start (); // write content echo 'What Ever You Want!' ; $content = ob_get_clean (); file_put_contents ( $cacheFile , $content ); echo $content ; } ?>
  • 24. Project 5 – rewrite variable <?php output_add_rewrite_var ( 'var' , 'value' ); echo '<a href=&quot;file.php&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a>' ; echo '<form action=&quot;script.php&quot; method=&quot;post&quot;> <input type=&quot;text&quot; name=&quot;var2&quot; /> </form><br>' ; print_r ( ob_list_handlers ()); ob_end_flush (); output_reset_rewrite_vars (); echo '<br><a href=&quot;file.php&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a>' ; echo '<form action=&quot;script.php&quot; method=&quot;post&quot;> <input type=&quot;text&quot; name=&quot;var2&quot; /> </form><br>' ; print_r ( ob_list_handlers ()); ?> <a href=&quot;file.php?var=value&quot;>link</a> <a href=&quot;http://example.com&quot;>link2</a> <form action=&quot;script.php&quot; method=&quot;post&quot;><input type=&quot;hidden&quot; name=&quot;var&quot; value=&quot;value&quot; />
  • 25. Project 6 – Less HTML less readable <?php function condense ( $buffer ){ // change new lines and tabs to single spaces $buffer = str_replace ( array ( &quot;&quot; , &quot;&quot; , &quot;&quot; , &quot;&quot; ), ' ' , $buffer ); // multispaces to single... $buffer = ereg_replace ( &quot; {2,}&quot; , ' ' , $buffer ); // remove single spaces between tags $buffer = str_replace ( &quot;> <&quot; , &quot;><&quot; , $buffer ); // remove single spaces around &nbsp; $buffer = str_replace ( &quot; &nbsp;&quot; , &quot;&nbsp;&quot; , $buffer ); $buffer = str_replace ( &quot;&nbsp; &quot; , &quot;&nbsp;&quot; , $buffer ); return $buffer ; } ob_start ( &quot; condense &quot; ); // your website ob_end_flush (); ?> Can Be Very Costly
  • 26. Project 7 – Tidyhandler <?php ob_start ( 'ob_tidyhandler' ); echo '<p>test</i>' ; ?> <!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 3.2//EN&quot;> <html> <head> <title></title> </head> <body> <p> test </p> </body> </html> http://ditio.net/2008/01/03/is-your-html-code-tidy/ Uncomment in php.ini 4 xampp ;extension=php_sybase_ct.dll ;extension=php_threads.dll extension=php_tidy.dll ;extension=php_timezonedb.dll ;extension=php_translit.dll
  • 27. Project 8 – Compression level <?php ini_set ( 'zlib.output_compression_level' , 8 ); ob_start ( &quot;ob_gzhandler&quot; ); // html ob_end_flush (); ?>
  • 28.
  • 29.
  • 30.
  • 31. Questions Sorry, we do not answer questions If you come across this document online, please refer to www.php.net or use a search engine to find your answers. Else if you catch me standing in front of you, then I will do my best to answer your questions.
  • 32.