SlideShare une entreprise Scribd logo
1  sur  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]

Contenu connexe

Dernier

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

En vedette

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
 

En vedette (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.