SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
SERVER INDEPENDENT
PROGRAMMING
By Eddo Rotman
   




                     Copyright © 2008, Zend Technologies Inc.
What's the point?

     • Save time
            • on deployment
            • on upgrades
            • on switching servers
            • on configuration changes
     •      Avoid frustration
     •      Professionalism




2|       Sep 17, 2008   |
Topics

 •   Constants
 •   Directives
 •   Functions
 •   Frameworks & Bootstrapping




3|   Sep 17, 2008   |
Constants

 • PHP has a lot of built-in constants
       •   PHP_EOL
       •   DIRECTORY_SEPERATOR
       •   PATH_SEPERATOR
       •   PHP_INT_MAX


                            PHP constants know better!




4|   Sep 17, 2008   |
Constants (cont)
      set_include_path('/usr/local/zend/share/ZendFramework:/home/eddo/library');




      set_include_path(   '/usr/local/zend/share/ZendFramework' . 
                          PATH_SEPERATOR . '/home/eddo/library');




      $fh = fopen('datadatafile.xml');




      $fh = fopen('data' . DIRECTORY_SEPERATOR . 'datafile.xml');




5|   Sep 17, 2008   |
Directives

 PHP has many directives which enable different
 configurations

 Most directives will be in your php.ini, though on some
 distros extensions' directives are separated to different
 files
                                       Never assume a
                                       directive's value!


 * in the following slides values in []
       are recommended values for development


6|   Sep 17, 2008   |
Directives (cont)

 There are four ways to mark a PHP script

 The following directives may be different on different
 machines
       • short_open_tag [off]
       • asp_tags [off]


 Always use full tags <?php ?> to make sure your
 application runs on every machine

 <?= is short tags!

7|   Sep 17, 2008   |
Directives (cont)

 PHP was created with some magic capabilities which may
 be changed through directives, like
       • register_globals [off]
       • magic_quotes_gpc [off]


 Assuming these are set to On is not only bad for
 portability, but may also be a security risk




8|   Sep 17, 2008   |
Directives (cont)

 Errors are a fact of life, so you should handle them

 Never assume the server is taking care of them for you
       • display_errors [on]
       • error_reporting [E_ALL | E_STRICT]




9|   Sep 17, 2008   |
Directives (cont)

  A few more directives that should be noted
         • max_execution_time
         • upload_max_filesize
         • include_path




10 |   Sep 17, 2008   |
Directives (cont)

  What can you do?
         • Use a strict php.ini file in production (based on php.ini-
           recommended)
         • Check values of important php directives in runtime
         • Change PHP_INI_ALL or PHP_INI_USER directives in runtime to
           fit your needs


                      PHP_INI_USER      Entry can be set in user scripts or in Windows registry
                      PHP_INI_PERDIR    Entry can be set in php.ini, .htaccess or httpd.conf
                      PHP_INI_SYSTEM    Entry can be set in php.ini or httpd.conf
                      PHP_INI_ALL       Entry can be set anywhere




11 |   Sep 17, 2008   |
Core Functions

  PHP functions may behave differently on different
  machines
         • Some may not work at all
         • Some may work strangely


  Which functions should we look for?
         • locale & time related functions [e.g. setlocale()]
         • file system related functions [e.g. chmod(), is_link()]
         • execution functions [e.g. proc_open(), shell_exec()]




12 |   Sep 17, 2008   |
Core Functions (cont)
       echo date('d­M­Y H:i:s');




       16­Sep­2008 02:06:58 // machine timezone was Asia/Jerusalem
       15­Sep­2008 23:06:58 // machine timezone was GMT




         Possible solution:

       date_default_timezone_set('GMT');
       echo date('d­M­Y H:i:s');




13 |   Sep 17, 2008   |
The Good Functions

  PHP has a few functions which may help us
  • sys_get_temp_dir()
  • tempnam()




14 |   Sep 17, 2008   |
Extensions' Functions

  API functions of PHP extensions may be missing

  If you need to use an extension – check that it is there
         • function_exists()
         • extension_loaded()




15 |   Sep 17, 2008   |
Disabled Functions

  Many shared hosting providers limit access to potentially
  hazardous functions, such as shell execution functions

  Disabling functions is done through disable_functions and
  disable_classes directives

  If a function is disabled, function_exists() on that
  function name will return false




16 |   Sep 17, 2008   |
Contexts

  A context class is a factory class which does the required
  action or returns the required class based on the relevant
  context

  By wrapping server specific functions in a context class,
  you can normalize the behavior of these functions to
  match any server




17 |   Sep 17, 2008   |
Contexts (cont)
       class Context_Os {

               /**
                * Execute a command
                * @param string $command
                * @return boolean
                */
               public function static exec($command) {
                   if (DIRECTORY_SEPARATOR === '') {
                        return Executer_Windows::exec($command);
                   } else {
                        return Executer_Linux::exec($command);
                   }
               }

       }




18 |       Sep 17, 2008   |
Frameworks

  Frameworks are good practice to limit the risk

  Never trust them until you know you can trust them

  They are not a bullet-proof solution to the problem




19 |   Sep 17, 2008   |
Bootstrapping

  • Use a different bootstrap file for development and for
       production
  •    Set all the directives you may during runtime in that
       bootstrap to limit the risk
  •    Check all the mandatory extensions you need are there
  •    Check for potentially missing functions which are vital
       for your application




20 |   Sep 17, 2008   |
Deployment Script

  If you don't wish to check for server integrity on each
  request in your bootstrap file, keep an integrity check
  script which does the heavier checks

  It won't save you from server changes or upgrades, unless
  you run it again




21 |   Sep 17, 2008   |
Conclusions

  • Get used to using constants
  • Check and set important
       directives
  •    Check for crucially needed
       extensions and functions
  •    Use a bootstrap file or a
       deployment script
  •    Be paranoid




22 |   Sep 17, 2008   |
Questions?




                    Now would be a great time to fill
                    in your evaluation forms :-)




23 Sep 17, 2008 |
 |

Contenu connexe

Similaire à Server Independent Programming

PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Toolsrjsmelo
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroSteven Pignataro
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and ExceptionsElegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and ExceptionsZendCon
 
Some tips to improve developer experience with Symfony
Some tips to improve developer experience with SymfonySome tips to improve developer experience with Symfony
Some tips to improve developer experience with Symfonytyomo4ka
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...OpenShift Origin
 
WordCamp LA 2014- Writing Code that Scales
WordCamp LA 2014-  Writing Code that ScalesWordCamp LA 2014-  Writing Code that Scales
WordCamp LA 2014- Writing Code that ScalesSpectrOMTech.com
 
Lesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsLesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsZendCon
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend FrameworkPhil Brown
 
PHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryPHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryMichael Spector
 
Extending JBoss EPP and Site Publisher your way
Extending JBoss EPP and Site Publisher your wayExtending JBoss EPP and Site Publisher your way
Extending JBoss EPP and Site Publisher your wayrafaelliu
 
meet.php #11 - Huston, we have an airbrake
meet.php #11 - Huston, we have an airbrakemeet.php #11 - Huston, we have an airbrake
meet.php #11 - Huston, we have an airbrakeMax Małecki
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 
Sprint 138
Sprint 138Sprint 138
Sprint 138ManageIQ
 
Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009PHPBelgium
 

Similaire à Server Independent Programming (20)

PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Tools
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and ExceptionsElegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and Exceptions
 
Some tips to improve developer experience with Symfony
Some tips to improve developer experience with SymfonySome tips to improve developer experience with Symfony
Some tips to improve developer experience with Symfony
 
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
 
WordCamp LA 2014- Writing Code that Scales
WordCamp LA 2014-  Writing Code that ScalesWordCamp LA 2014-  Writing Code that Scales
WordCamp LA 2014- Writing Code that Scales
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
Lesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsLesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP Applications
 
NodeJS
NodeJSNodeJS
NodeJS
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
R12.2 dba
R12.2 dbaR12.2 dba
R12.2 dba
 
It gilde 20150209
It gilde 20150209It gilde 20150209
It gilde 20150209
 
PHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryPHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success Story
 
Extending JBoss EPP and Site Publisher your way
Extending JBoss EPP and Site Publisher your wayExtending JBoss EPP and Site Publisher your way
Extending JBoss EPP and Site Publisher your way
 
meet.php #11 - Huston, we have an airbrake
meet.php #11 - Huston, we have an airbrakemeet.php #11 - Huston, we have an airbrake
meet.php #11 - Huston, we have an airbrake
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Sprint 138
Sprint 138Sprint 138
Sprint 138
 
Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 

Plus de ZendCon

Framework Shootout
Framework ShootoutFramework Shootout
Framework ShootoutZendCon
 
Zend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZendCon
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
 
PHP on Windows - What's New
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's NewZendCon
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudZendCon
 
I18n with PHP 5.3
I18n with PHP 5.3I18n with PHP 5.3
I18n with PHP 5.3ZendCon
 
Cloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go AwayCloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go AwayZendCon
 
Planning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local DatabasesPlanning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local DatabasesZendCon
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework ApplicationZendCon
 
Enterprise-Class PHP Security
Enterprise-Class PHP SecurityEnterprise-Class PHP Security
Enterprise-Class PHP SecurityZendCon
 
PHP and IBM i - Database Alternatives
PHP and IBM i - Database AlternativesPHP and IBM i - Database Alternatives
PHP and IBM i - Database AlternativesZendCon
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZendCon
 
Application Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingApplication Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingZendCon
 
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...ZendCon
 
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilitySolving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilityZendCon
 
Joe Staner Zend Con 2008
Joe Staner Zend Con 2008Joe Staner Zend Con 2008
Joe Staner Zend Con 2008ZendCon
 
Tiery Eyed
Tiery EyedTiery Eyed
Tiery EyedZendCon
 
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...ZendCon
 
DB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications SessionDB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications SessionZendCon
 
Digital Identity
Digital IdentityDigital Identity
Digital IdentityZendCon
 

Plus de ZendCon (20)

Framework Shootout
Framework ShootoutFramework Shootout
Framework Shootout
 
Zend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZend_Tool: Practical use and Extending
Zend_Tool: Practical use and Extending
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
PHP on Windows - What's New
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's New
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
I18n with PHP 5.3
I18n with PHP 5.3I18n with PHP 5.3
I18n with PHP 5.3
 
Cloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go AwayCloud Computing: The Hard Problems Never Go Away
Cloud Computing: The Hard Problems Never Go Away
 
Planning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local DatabasesPlanning for Synchronization with Browser-Local Databases
Planning for Synchronization with Browser-Local Databases
 
Magento - a Zend Framework Application
Magento - a Zend Framework ApplicationMagento - a Zend Framework Application
Magento - a Zend Framework Application
 
Enterprise-Class PHP Security
Enterprise-Class PHP SecurityEnterprise-Class PHP Security
Enterprise-Class PHP Security
 
PHP and IBM i - Database Alternatives
PHP and IBM i - Database AlternativesPHP and IBM i - Database Alternatives
PHP and IBM i - Database Alternatives
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security Considerations
 
Application Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server TracingApplication Diagnosis with Zend Server Tracing
Application Diagnosis with Zend Server Tracing
 
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
Insights from the Experts: How PHP Leaders Are Transforming High-Impact PHP A...
 
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and ScalabilitySolving the C20K problem: Raising the bar in PHP Performance and Scalability
Solving the C20K problem: Raising the bar in PHP Performance and Scalability
 
Joe Staner Zend Con 2008
Joe Staner Zend Con 2008Joe Staner Zend Con 2008
Joe Staner Zend Con 2008
 
Tiery Eyed
Tiery EyedTiery Eyed
Tiery Eyed
 
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
Make your PHP Application Software-as-a-Service (SaaS) Ready with the Paralle...
 
DB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications SessionDB2 Storage Engine for MySQL and Open Source Applications Session
DB2 Storage Engine for MySQL and Open Source Applications Session
 
Digital Identity
Digital IdentityDigital Identity
Digital Identity
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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...
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Server Independent Programming

  • 1. SERVER INDEPENDENT PROGRAMMING By Eddo Rotman   Copyright © 2008, Zend Technologies Inc.
  • 2. What's the point? • Save time • on deployment • on upgrades • on switching servers • on configuration changes • Avoid frustration • Professionalism 2| Sep 17, 2008 |
  • 3. Topics • Constants • Directives • Functions • Frameworks & Bootstrapping 3| Sep 17, 2008 |
  • 4. Constants • PHP has a lot of built-in constants • PHP_EOL • DIRECTORY_SEPERATOR • PATH_SEPERATOR • PHP_INT_MAX PHP constants know better! 4| Sep 17, 2008 |
  • 5. Constants (cont) set_include_path('/usr/local/zend/share/ZendFramework:/home/eddo/library'); set_include_path( '/usr/local/zend/share/ZendFramework' .  PATH_SEPERATOR . '/home/eddo/library'); $fh = fopen('datadatafile.xml'); $fh = fopen('data' . DIRECTORY_SEPERATOR . 'datafile.xml'); 5| Sep 17, 2008 |
  • 6. Directives PHP has many directives which enable different configurations Most directives will be in your php.ini, though on some distros extensions' directives are separated to different files Never assume a directive's value! * in the following slides values in [] are recommended values for development 6| Sep 17, 2008 |
  • 7. Directives (cont) There are four ways to mark a PHP script The following directives may be different on different machines • short_open_tag [off] • asp_tags [off] Always use full tags <?php ?> to make sure your application runs on every machine <?= is short tags! 7| Sep 17, 2008 |
  • 8. Directives (cont) PHP was created with some magic capabilities which may be changed through directives, like • register_globals [off] • magic_quotes_gpc [off] Assuming these are set to On is not only bad for portability, but may also be a security risk 8| Sep 17, 2008 |
  • 9. Directives (cont) Errors are a fact of life, so you should handle them Never assume the server is taking care of them for you • display_errors [on] • error_reporting [E_ALL | E_STRICT] 9| Sep 17, 2008 |
  • 10. Directives (cont) A few more directives that should be noted • max_execution_time • upload_max_filesize • include_path 10 | Sep 17, 2008 |
  • 11. Directives (cont) What can you do? • Use a strict php.ini file in production (based on php.ini- recommended) • Check values of important php directives in runtime • Change PHP_INI_ALL or PHP_INI_USER directives in runtime to fit your needs PHP_INI_USER   Entry can be set in user scripts or in Windows registry PHP_INI_PERDIR  Entry can be set in php.ini, .htaccess or httpd.conf PHP_INI_SYSTEM  Entry can be set in php.ini or httpd.conf PHP_INI_ALL  Entry can be set anywhere 11 | Sep 17, 2008 |
  • 12. Core Functions PHP functions may behave differently on different machines • Some may not work at all • Some may work strangely Which functions should we look for? • locale & time related functions [e.g. setlocale()] • file system related functions [e.g. chmod(), is_link()] • execution functions [e.g. proc_open(), shell_exec()] 12 | Sep 17, 2008 |
  • 13. Core Functions (cont) echo date('d­M­Y H:i:s'); 16­Sep­2008 02:06:58 // machine timezone was Asia/Jerusalem 15­Sep­2008 23:06:58 // machine timezone was GMT Possible solution: date_default_timezone_set('GMT'); echo date('d­M­Y H:i:s'); 13 | Sep 17, 2008 |
  • 14. The Good Functions PHP has a few functions which may help us • sys_get_temp_dir() • tempnam() 14 | Sep 17, 2008 |
  • 15. Extensions' Functions API functions of PHP extensions may be missing If you need to use an extension – check that it is there • function_exists() • extension_loaded() 15 | Sep 17, 2008 |
  • 16. Disabled Functions Many shared hosting providers limit access to potentially hazardous functions, such as shell execution functions Disabling functions is done through disable_functions and disable_classes directives If a function is disabled, function_exists() on that function name will return false 16 | Sep 17, 2008 |
  • 17. Contexts A context class is a factory class which does the required action or returns the required class based on the relevant context By wrapping server specific functions in a context class, you can normalize the behavior of these functions to match any server 17 | Sep 17, 2008 |
  • 18. Contexts (cont) class Context_Os { /**  * Execute a command  * @param string $command  * @return boolean  */ public function static exec($command) { if (DIRECTORY_SEPARATOR === '') { return Executer_Windows::exec($command); } else { return Executer_Linux::exec($command); } } } 18 | Sep 17, 2008 |
  • 19. Frameworks Frameworks are good practice to limit the risk Never trust them until you know you can trust them They are not a bullet-proof solution to the problem 19 | Sep 17, 2008 |
  • 20. Bootstrapping • Use a different bootstrap file for development and for production • Set all the directives you may during runtime in that bootstrap to limit the risk • Check all the mandatory extensions you need are there • Check for potentially missing functions which are vital for your application 20 | Sep 17, 2008 |
  • 21. Deployment Script If you don't wish to check for server integrity on each request in your bootstrap file, keep an integrity check script which does the heavier checks It won't save you from server changes or upgrades, unless you run it again 21 | Sep 17, 2008 |
  • 22. Conclusions • Get used to using constants • Check and set important directives • Check for crucially needed extensions and functions • Use a bootstrap file or a deployment script • Be paranoid 22 | Sep 17, 2008 |
  • 23. Questions? Now would be a great time to fill in your evaluation forms :-) 23 Sep 17, 2008 | |