SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
PHP Sucks?!
Simon Neidhold, Stefan Wiegreffe, ICANS GmbH
www.icans-gmbh.com




                                               1	
  
Über uns



Simon	
  Neidhold	
                   Stefan	
  Wiegreffe	
  
So&ware	
  Engineer	
                 Team	
  Lead	
  Web	
  Development	
  
simon.neidhold@icans-­‐gmbh.com	
     stefan.wiegreffe@icans-­‐gmbh.com	
  
@sneidhold	
                          @swiegreffe	
  




                                                                               2	
  
                                                                               2
PHP sucks?!




              3	
  
              3
Die Nadel im Heuhaufen




                         4	
  
                         4
to, _to_, 2




              5	
  
              5
Unterm Strich zählt die Semantik




                                   6	
  
                                   6
Next: Wordpress




                  7	
  
                  7
Standard-Template: index.php

<?php!
    /**!
       * The main template file.!
       *!
       * This is the most generic template file in a WordPress theme [...].!
       *!
       * @package WordPress!
       * @subpackage Twenty_Eleven!
       */!
    !
get_header(); ?>!
!
    <div id="primary">!
        <div id="content" role="main">!
!
        <?php if ( have_posts() ) : ?>!
!
            <?php twentyeleven_content_nav( 'nav-above' ); ?>!
!
            <?php /* Start the Loop */ ?>!
            <?php while ( have_posts() ) : the_post(); ?>!
!
                <?php get_template_part( 'content', get_post_format() ); ?>!
    !
            <?php endwhile; ?>!
!
            [...]!
                                                                               8	
  
                                                                               8
the_post()

    the_post()	
  ist	
  deklariert	
  in	
  Zeile	
  773	
  in	
  wp-­‐includes/query.php:	
  	
  

/**!
 * Iterate the post index in the loop.!
 *!
 * @see WP_Query::the_post()!
 * @since 1.5.0!
 * @uses $wp_query!
 */!
function the_post() {!
     global $wp_query;!
!
          $wp_query->the_post();!
}!




                                                                                                      9	
  
                                                                                                      9
WTF??

    WP_Query::the_post()	
  ist	
  deklariert	
  in	
  Zeile	
  2778	
  in	
  wp-­‐includes/query.php:	
  	
  

class WP_Query {!
!
         /**!
            * Sets up the current post.!
            *!
            * Retrieves the next post, sets up the post, sets the 'in the loop'!
            * property to true.!
            *!
            * @since 1.5.0!
            * @access public!
            * @uses $post!
            * @uses do_action_ref_array() Calls 'loop_start' if loop has just started!
            */!
         function the_post() {!
                global $post;!
                $this->in_the_loop = true;!
                !
                if ( $this->current_post == -1 ) // loop has just started!
                        do_action_ref_array('loop_start', array(&$this));!
                  !
                    $post = $this->next_post();!
                setup_postdata($post);!
         }!
!
}	
                                                                                                              10	
  
                                                                                                                 10
Next: Debugging!



<?php!
    require "../../global_setting.php";!
    include "../../custom/functions.php" ;!
      !
        $someId = 1337;!
        $sql = "INSERT INTO some_table (`name`, `date`, `count`) ";!
        $sql .= "VALUES ('{$someId}', " . time() - mktime(0,0,0) . " , 6)";!
        !
    // echo '$sql: '; !
    // var_dump($sql);!
    // die();!
    !




Die	
  Debug-­‐Ausgabe	
  wäre	
  übrigens	
  $sql:	
  string(16)	
  "-­‐1322434800	
  ,	
  6)"	
  




                                                                                                      11	
  
                                                                                                      11
Schwache, dynamische Typisierung



echo   (true == "false");!
  =>   1!
echo   (true === "false");!
  =>   !
echo   (true == "");!
  =>     !
!
echo   (10 + 012);!
  =>   20!
echo   (10 + 09);!
  =>   10!
!
echo   010 + 5;!
  =>   13!
echo   "010" + 5;!
  =>   15!
!




                                   12	
  
                                   12
World Wide Web




                 13	
  
                 13
Twitter JSON API
{!
     "completed_in":0.209,!
     "max_id":141283786544513025,!
     "max_id_str":"141283786544513025",!
     "next_page":"?page=2&max_id=141283786544513025&q=php%20sucks&rpp=1",!
     "page":1,!
     "query":"php+sucks",!
     "refresh_url":"?since_id=141283786544513025&q=php%20sucks",!
     "results":[{"created_at":"Mon,!
      28 Nov 2011 22:34:14 +0000",!
     "from_user":"infomancien",!
     "from_user_id":79284740,!
     "from_user_id_str":"79284740",!
     "from_user_name":"Infomancien",!
     "geo":null,!
     "id":141283786544513025,!
     "id_str":"141283786544513025",!
     "iso_language_code":"en",!
     "metadata":{"result_type":"recent"},!
     "profile_image_url":"http://a3.twimg.com/[...]/alicelascombe_normal.png",!
     "source":"&lt;a href=&quot;http://www.hootsuite.com[...]",!
     "text":"(@rww) Entrepreneurship Sucks - The sad state of affairs is that working !
             for yourself is really just a worse version... http://t.co/BEctTyFw",!
     "to_user":null,!
     "to_user_id":null,!
     "to_user_id_str":null,!
     "to_user_name":null}],!
     "results_per_page":1,!
     "since_id":0,!
     "since_id_str":"0"!
}!

                                                                                          14	
  
                                                                                          14
(Rapid) Prototyping FTW!




                           15	
  
                           15
Vom Prototyp zum Produkt




                           ???




                                 16	
  
                                 16
Das finale Produkt mit echter Technologien umsetzen




§  Enterprise-Grade Application Server

§  Spring

§  Java Server Faces

§  Hibernate

§  Junit




                                                      17	
  
                                                      17
PHP ist (uns) bereits bekannt.




                                 18	
  
Application Server


§  Ein beliebiger Webserver

§  Schmaler Footprint

 •  PokerStrategy.com: maximal 8MB je Request
 •  JBoss + Liferay: 1,2 GB für Bootstrapping




                                                19	
  
                                                19
Application Server / Skalierung über FPM




                                           20	
  
                                           20
Spring / Java Server Faces




•  Weit verbreitet            •  100% OOP
•  Beeindruckender Umfang     •  Lose gekoppelt
 - PDF- Handling              •  Annotations
 - Social Media Connectoren   •  Dependency Injection




                                                        21	
  
                                                        21
Hibernate / JUnit




 DBAL	
  /	
  ORM	
  für	
     Dynamic	
  Mocks	
  
 -­‐  MySQL	
  
 -­‐  SQLite	
  
 -­‐  PostgreSQL	
  
 -­‐  MSSQL	
  
 -­‐  Oracle	
  
 	
  
 ODM	
  für	
  
 -­‐  CouchDB	
  
 -­‐  MongoDB	
  
 -­‐  PHPCR	
  


                                                      22	
  
                                                      22
Nicht nur das PHP-Ökosystem rockt.




                                     23	
  
PHP arbeitet wie das WWW




                  §  ... ist Request-Basiert

                  §  ... hat keine strikte Typisierung




                                                          24	
  
                                                          24
Batteries included



§  XML, Image/Audio-Manipulation, Zip-Files, OAuth, Cryptography

§  mächtige String- und Array-Funktionen

§  Reflection

§  PECL/Pear




   USE	
                    IMPORT	
                     DLLs	
  

                                                                    25	
  
                                                                    25
Auch das ist PHP


§  Autoloading

§  Namespacing

§  Type Hinting

§  Anonyme Funktionen

§  Abstrakte Klassen

§  Interfaces

§  private, protected, public, final

§  Exceptions




                                        26	
  
                                        26
Sprache oder Entwickler – Wer suckt denn nun?




               Mit	
  PHP	
  kann	
  man	
  viel	
  erreichen	
  


               Es	
  ist	
  sehr	
  wichWg,	
  gute	
  Entwickler	
  zu	
  haben	
  




                                                                                       27	
  
                                                                                       27
Erfolgreich mit PHP




                      28	
  
                      28
PokerStrategy.com in Zahlen


§  70 Mio Seitenabrufe / Monat
                                                                7%	
  
                                                  7%	
   8%	
  
§  6 Mio Reg. User

§  500.000 LOC                                                               14%	
  
                                                           3%	
   4%	
  
                                                             3%	
  
§  >50 TB Traffic / Monat

§  19 Sprachen                                                              6%	
  

                                         4%	
     Rest	
  of	
  the	
  world:	
  
§  Insgesamt ~50 Server
 •  2 Load Balancer
 •  10 App-Server
                                     3%	
  
                                                      41%	
  
 •  15 DB-Server
 •  Video Delivery, Community, ...




                                                                                        29	
  
                                                                                        29
Case Study: ID-Check


                                        CASE STUDY
§  Problem: Fraud

§  Validierung des Nutzers notwendig

§  Upload von Dokumenten




                                                30	
  
                                                30
ID-Check: Screenshot


                       CASE STUDY




                               31	
  
                               31
ID-Check: Requirements


§  Privacy                                         CASE STUDY
 •  Nur Thumbnail nach extern ausliefern
 •  nur an den Uploader

§  Performance
 •  Uploads (bis 20MB JPEG) in 2 Größen umrechnen
 •  Erwartete Last:
   -  Max. 10.000 Bilder / Tag
   -  Max. 4.000 Bilder / Stunde

§  Security
 •  Lastkontrolle / Missbrauch verhindern
 •  Viren-Check

§  Funktional
 •  Thumbnail für User
 •  Preview in mittlerer Größe

                                                            32	
  
                                                            32
ID-Check: Basic Setup


                                                                            CASE STUDY




                                            ID-Check Server




                                                 API



                                     HTTP                     HTTP



                        AJAX Proxy


                                                                     Backoffice
                         Frontend




                                                                                    33	
  
                                                                                    33
ID-Check: XSRF-Protection


                                                                                CASE STUDY




                                                ID-Check Server


                            Validate
               Datenbank     Token



                                                     API



                Create                   HTTP                     HTTP
                Token


                            AJAX Proxy


                                                                         Backoffice
                              Frontend




                                                                                        34	
  
                                                                                        34
Uploads von nicht angemeldeten Usern verhindern


                                                                                       CASE STUDY

                           Check
 SSO Service               Login
                           State

                                                       ID-Check Server


                                   Validate
               Datenbank            Token



                                                            API
      Check
      Login
      State
                Create                          HTTP                     HTTP
                Token


                                   AJAX Proxy


                                                                                Backoffice
                                     Frontend




                                                                                               35	
  
                                                                                               35
ID-Check: Performance / Skalierung


                                                      CASE STUDY




§  4 Worker / 4 Kerne

§  Synchroner Prozess für Anti-Virus und Thumbnail

§  Asynchron für mittlere Größe




                                                              36	
  
                                                              36
ID-Check: Fazit


                                                                CASE STUDY




                  §  Entwicklungszeit: 8 Wochen

                  §  Server virtualisiert ohne Last-Probleme

                                                                        37	
  
                                                                        37
„PHP-Entwickler sind aber @!#*$“




                                   38	
  
Auch / Gerade bei PHP: Maximale Qualitätsstandards


§  Nur exzellente Entwickler einstellen

§  Continuous Improvement
   •  Konferenzen, Zertifizierungen, Schulungen, Pair Programming, ...

§  Continuous Integration (Jenkins)
   •  Code Sniffer, Mess Detection
   •  Coding Standards, Unit-Tests

§  Regelmäßige Code – Reviews

§  ...




                                                                         39	
  
                                                                         39
Roundup


§  Man kann in jeder Sprache Schrott machen

§  Der Entwickler macht den Unterschied

§  Die gewählte Architektur ist wichtiger als die gewählte Sprache



§  Für ICANS ist PHP auch langfristig die richtige Entscheidung




                                                                      40	
  
                                                                      40
www.icans-­‐gmbh.com	
  
                           41	
  
ICANS GmbH
Valentinskamp 18
20354 Hamburg
Germany


Phone:   +49 40 22 63 82 9-0
Fax:     +49 40 38 67 15 92


Web: www.icans-gmbh.com
	
  



                               42	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Websemantik: Die nächsten Schritte
Websemantik: Die nächsten SchritteWebsemantik: Die nächsten Schritte
Websemantik: Die nächsten SchritteMichael Jendryschik
 
Einstieg in Xpath für SEO (Campixx2021)
Einstieg in Xpath für SEO (Campixx2021)Einstieg in Xpath für SEO (Campixx2021)
Einstieg in Xpath für SEO (Campixx2021)Sebastian Adler
 
Sh optifind praesentation_20130311
Sh optifind praesentation_20130311Sh optifind praesentation_20130311
Sh optifind praesentation_20130311Stefan Moises
 
HTML5 und node.js Grundlagen
HTML5 und node.js GrundlagenHTML5 und node.js Grundlagen
HTML5 und node.js GrundlagenMayflower GmbH
 
Web-Automatisierung mit WWW::Mechanize
Web-Automatisierung mit WWW::MechanizeWeb-Automatisierung mit WWW::Mechanize
Web-Automatisierung mit WWW::MechanizeThomas Fahle
 
Seminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusSeminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusFabian Becker
 
An Introduction to Ruby On Rails
An Introduction to Ruby On RailsAn Introduction to Ruby On Rails
An Introduction to Ruby On RailsJonathan Weiss
 
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...NETWAYS
 

Was ist angesagt? (9)

Websemantik: Die nächsten Schritte
Websemantik: Die nächsten SchritteWebsemantik: Die nächsten Schritte
Websemantik: Die nächsten Schritte
 
Rack-Middleware
Rack-MiddlewareRack-Middleware
Rack-Middleware
 
Einstieg in Xpath für SEO (Campixx2021)
Einstieg in Xpath für SEO (Campixx2021)Einstieg in Xpath für SEO (Campixx2021)
Einstieg in Xpath für SEO (Campixx2021)
 
Sh optifind praesentation_20130311
Sh optifind praesentation_20130311Sh optifind praesentation_20130311
Sh optifind praesentation_20130311
 
HTML5 und node.js Grundlagen
HTML5 und node.js GrundlagenHTML5 und node.js Grundlagen
HTML5 und node.js Grundlagen
 
Web-Automatisierung mit WWW::Mechanize
Web-Automatisierung mit WWW::MechanizeWeb-Automatisierung mit WWW::Mechanize
Web-Automatisierung mit WWW::Mechanize
 
Seminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-MechanismusSeminar Joomla 1.5 SEF-Mechanismus
Seminar Joomla 1.5 SEF-Mechanismus
 
An Introduction to Ruby On Rails
An Introduction to Ruby On RailsAn Introduction to Ruby On Rails
An Introduction to Ruby On Rails
 
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
OSMC 2008 | Programmierung von Nagios-Plugins für NetApp Speichergeräte by In...
 

Andere mochten auch

Craig's Letter of Recommendation
Craig's Letter of RecommendationCraig's Letter of Recommendation
Craig's Letter of RecommendationCraig Braddick
 
Catalogo 16
Catalogo 16Catalogo 16
Catalogo 16Andrea M
 
Workshop Soziale Netzwerke
Workshop Soziale NetzwerkeWorkshop Soziale Netzwerke
Workshop Soziale Netzwerkemarull
 
La planificació sociocultural
La planificació socioculturalLa planificació sociocultural
La planificació socioculturalcarlesmonclus
 
Publicidad
PublicidadPublicidad
Publicidaddanidaco
 
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...iSOCO
 
Gestion exitosa del cambiov1
Gestion exitosa del cambiov1Gestion exitosa del cambiov1
Gestion exitosa del cambiov1SABMiller
 
Nd p olswang nombramiento j felix de luis 31 05 2011
Nd p olswang nombramiento j felix de luis 31 05 2011Nd p olswang nombramiento j felix de luis 31 05 2011
Nd p olswang nombramiento j felix de luis 31 05 2011evercom
 
Tema 4 El resurgir de las ciudades
Tema 4 El resurgir de las ciudadesTema 4 El resurgir de las ciudades
Tema 4 El resurgir de las ciudadesfrancisco gonzalez
 
Orientación y apoyo psicológico a adolescentes adictos a internet. pf
Orientación y apoyo psicológico a adolescentes adictos a internet. pfOrientación y apoyo psicológico a adolescentes adictos a internet. pf
Orientación y apoyo psicológico a adolescentes adictos a internet. pfExpectativas
 
Medidas de tendencia central
Medidas de tendencia centralMedidas de tendencia central
Medidas de tendencia centralMary Corado
 
The World of Ludus
The World of LudusThe World of Ludus
The World of LudusJesse Schell
 
La desconfianza online en Bolivia - Mariano Cabrera Lanfranconi
La desconfianza online en Bolivia - Mariano Cabrera LanfranconiLa desconfianza online en Bolivia - Mariano Cabrera Lanfranconi
La desconfianza online en Bolivia - Mariano Cabrera LanfranconiMariano Cabrera Lanfranconi
 
Internet of Things: Identity & Security with Open Standards
Internet of Things: Identity & Security with Open StandardsInternet of Things: Identity & Security with Open Standards
Internet of Things: Identity & Security with Open StandardsGeorge Fletcher
 
Catalogo STANHOME
Catalogo STANHOMECatalogo STANHOME
Catalogo STANHOMEvariedad
 
Currículo de secretaria y asistente ejecutiva itel 2016
Currículo de secretaria y asistente ejecutiva  itel 2016Currículo de secretaria y asistente ejecutiva  itel 2016
Currículo de secretaria y asistente ejecutiva itel 2016Arthuro Pérez
 

Andere mochten auch (20)

Craig's Letter of Recommendation
Craig's Letter of RecommendationCraig's Letter of Recommendation
Craig's Letter of Recommendation
 
Catalogo 16
Catalogo 16Catalogo 16
Catalogo 16
 
Brijesh Prabhakar July 18
Brijesh Prabhakar  July 18Brijesh Prabhakar  July 18
Brijesh Prabhakar July 18
 
Workshop Soziale Netzwerke
Workshop Soziale NetzwerkeWorkshop Soziale Netzwerke
Workshop Soziale Netzwerke
 
La planificació sociocultural
La planificació socioculturalLa planificació sociocultural
La planificació sociocultural
 
Amigo plus
Amigo plusAmigo plus
Amigo plus
 
Publicidad
PublicidadPublicidad
Publicidad
 
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...
Jornada Innovación Madrid. Ponencia 'De los retos a las iniciativas pasando p...
 
Gestion exitosa del cambiov1
Gestion exitosa del cambiov1Gestion exitosa del cambiov1
Gestion exitosa del cambiov1
 
Nd p olswang nombramiento j felix de luis 31 05 2011
Nd p olswang nombramiento j felix de luis 31 05 2011Nd p olswang nombramiento j felix de luis 31 05 2011
Nd p olswang nombramiento j felix de luis 31 05 2011
 
Tema 4 El resurgir de las ciudades
Tema 4 El resurgir de las ciudadesTema 4 El resurgir de las ciudades
Tema 4 El resurgir de las ciudades
 
Orientación y apoyo psicológico a adolescentes adictos a internet. pf
Orientación y apoyo psicológico a adolescentes adictos a internet. pfOrientación y apoyo psicológico a adolescentes adictos a internet. pf
Orientación y apoyo psicológico a adolescentes adictos a internet. pf
 
Medidas de tendencia central
Medidas de tendencia centralMedidas de tendencia central
Medidas de tendencia central
 
The World of Ludus
The World of LudusThe World of Ludus
The World of Ludus
 
La desconfianza online en Bolivia - Mariano Cabrera Lanfranconi
La desconfianza online en Bolivia - Mariano Cabrera LanfranconiLa desconfianza online en Bolivia - Mariano Cabrera Lanfranconi
La desconfianza online en Bolivia - Mariano Cabrera Lanfranconi
 
Internet of Things: Identity & Security with Open Standards
Internet of Things: Identity & Security with Open StandardsInternet of Things: Identity & Security with Open Standards
Internet of Things: Identity & Security with Open Standards
 
Catalogo STANHOME
Catalogo STANHOMECatalogo STANHOME
Catalogo STANHOME
 
Resume_Prakash Natarajan
Resume_Prakash NatarajanResume_Prakash Natarajan
Resume_Prakash Natarajan
 
Currículo de secretaria y asistente ejecutiva itel 2016
Currículo de secretaria y asistente ejecutiva  itel 2016Currículo de secretaria y asistente ejecutiva  itel 2016
Currículo de secretaria y asistente ejecutiva itel 2016
 
Becu guia-matematica1
Becu guia-matematica1Becu guia-matematica1
Becu guia-matematica1
 

Ähnlich wie PHP Sucks?!

Eigene Themes from Scratch
Eigene Themes from ScratchEigene Themes from Scratch
Eigene Themes from ScratchStefan Fröhlich
 
Entwicklung mit Chef und Vagrant - PHPUG HH
Entwicklung mit Chef und Vagrant - PHPUG HHEntwicklung mit Chef und Vagrant - PHPUG HH
Entwicklung mit Chef und Vagrant - PHPUG HHFlorian Holzhauer
 
German: Softwareprodukte aus einem Source Code mit Javascript
German: Softwareprodukte aus einem Source Code mit JavascriptGerman: Softwareprodukte aus einem Source Code mit Javascript
German: Softwareprodukte aus einem Source Code mit JavascriptRalf Schwoebel
 
HTML5-Legacy-Anwendungen
HTML5-Legacy-AnwendungenHTML5-Legacy-Anwendungen
HTML5-Legacy-AnwendungenJonathan Weiß
 
Open icf (open identity connector framework) @ forgerock deutsch
Open icf (open identity connector framework) @ forgerock   deutschOpen icf (open identity connector framework) @ forgerock   deutsch
Open icf (open identity connector framework) @ forgerock deutschHanns Nolan
 
OSMC 2014: Icinga Web 2 kann mehr | Thomas Gelf
OSMC 2014: Icinga Web 2 kann mehr | Thomas GelfOSMC 2014: Icinga Web 2 kann mehr | Thomas Gelf
OSMC 2014: Icinga Web 2 kann mehr | Thomas GelfNETWAYS
 
Icinga 2009 at Nagios Workshop
Icinga 2009 at Nagios WorkshopIcinga 2009 at Nagios Workshop
Icinga 2009 at Nagios WorkshopIcinga
 
Drupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickDrupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickAmazee Labs
 
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.David Jardin
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit RustJens Siebert
 
Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Daniel Havlik
 
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhenDietrichRordorf
 

Ähnlich wie PHP Sucks?! (20)

Hdc2012 cordova-präsi
Hdc2012 cordova-präsiHdc2012 cordova-präsi
Hdc2012 cordova-präsi
 
Eigene Themes from Scratch
Eigene Themes from ScratchEigene Themes from Scratch
Eigene Themes from Scratch
 
Entwicklung mit Chef und Vagrant - PHPUG HH
Entwicklung mit Chef und Vagrant - PHPUG HHEntwicklung mit Chef und Vagrant - PHPUG HH
Entwicklung mit Chef und Vagrant - PHPUG HH
 
node.js
node.jsnode.js
node.js
 
Webapplikationen mit Node.js
Webapplikationen mit Node.jsWebapplikationen mit Node.js
Webapplikationen mit Node.js
 
German: Softwareprodukte aus einem Source Code mit Javascript
German: Softwareprodukte aus einem Source Code mit JavascriptGerman: Softwareprodukte aus einem Source Code mit Javascript
German: Softwareprodukte aus einem Source Code mit Javascript
 
HTML5-Legacy-Anwendungen
HTML5-Legacy-AnwendungenHTML5-Legacy-Anwendungen
HTML5-Legacy-Anwendungen
 
Open icf (open identity connector framework) @ forgerock deutsch
Open icf (open identity connector framework) @ forgerock   deutschOpen icf (open identity connector framework) @ forgerock   deutsch
Open icf (open identity connector framework) @ forgerock deutsch
 
OSMC 2014: Icinga Web 2 kann mehr | Thomas Gelf
OSMC 2014: Icinga Web 2 kann mehr | Thomas GelfOSMC 2014: Icinga Web 2 kann mehr | Thomas Gelf
OSMC 2014: Icinga Web 2 kann mehr | Thomas Gelf
 
Offline Arbeiten
Offline ArbeitenOffline Arbeiten
Offline Arbeiten
 
Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1Web Entwicklung mit PHP - Teil 1
Web Entwicklung mit PHP - Teil 1
 
Icinga 2009 at Nagios Workshop
Icinga 2009 at Nagios WorkshopIcinga 2009 at Nagios Workshop
Icinga 2009 at Nagios Workshop
 
Ruby on Rails SS09 06
Ruby on Rails SS09 06Ruby on Rails SS09 06
Ruby on Rails SS09 06
 
Drupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickDrupal 7 Einblick und Ausblick
Drupal 7 Einblick und Ausblick
 
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.
Nooku, Molajo & Co - Joomla! Distributionen. Oder Forks.
 
Node.js für Webapplikationen
Node.js für WebapplikationenNode.js für Webapplikationen
Node.js für Webapplikationen
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit Rust
 
Fanstatic pycon.de 2012
Fanstatic pycon.de 2012Fanstatic pycon.de 2012
Fanstatic pycon.de 2012
 
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen
10 Stunden / 5 Massnahmen: Sicherheit einer Web App erhöhen
 
Ruby on Rails SS09 04
Ruby on Rails SS09 04Ruby on Rails SS09 04
Ruby on Rails SS09 04
 

PHP Sucks?!

  • 1. PHP Sucks?! Simon Neidhold, Stefan Wiegreffe, ICANS GmbH www.icans-gmbh.com 1  
  • 2. Über uns Simon  Neidhold   Stefan  Wiegreffe   So&ware  Engineer   Team  Lead  Web  Development   simon.neidhold@icans-­‐gmbh.com   stefan.wiegreffe@icans-­‐gmbh.com   @sneidhold   @swiegreffe   2   2
  • 3. PHP sucks?! 3   3
  • 4. Die Nadel im Heuhaufen 4   4
  • 5. to, _to_, 2 5   5
  • 6. Unterm Strich zählt die Semantik 6   6
  • 8. Standard-Template: index.php <?php! /**! * The main template file.! *! * This is the most generic template file in a WordPress theme [...].! *! * @package WordPress! * @subpackage Twenty_Eleven! */! ! get_header(); ?>! ! <div id="primary">! <div id="content" role="main">! ! <?php if ( have_posts() ) : ?>! ! <?php twentyeleven_content_nav( 'nav-above' ); ?>! ! <?php /* Start the Loop */ ?>! <?php while ( have_posts() ) : the_post(); ?>! ! <?php get_template_part( 'content', get_post_format() ); ?>! ! <?php endwhile; ?>! ! [...]! 8   8
  • 9. the_post() the_post()  ist  deklariert  in  Zeile  773  in  wp-­‐includes/query.php:     /**! * Iterate the post index in the loop.! *! * @see WP_Query::the_post()! * @since 1.5.0! * @uses $wp_query! */! function the_post() {! global $wp_query;! ! $wp_query->the_post();! }! 9   9
  • 10. WTF?? WP_Query::the_post()  ist  deklariert  in  Zeile  2778  in  wp-­‐includes/query.php:     class WP_Query {! ! /**! * Sets up the current post.! *! * Retrieves the next post, sets up the post, sets the 'in the loop'! * property to true.! *! * @since 1.5.0! * @access public! * @uses $post! * @uses do_action_ref_array() Calls 'loop_start' if loop has just started! */! function the_post() {! global $post;! $this->in_the_loop = true;! ! if ( $this->current_post == -1 ) // loop has just started! do_action_ref_array('loop_start', array(&$this));! ! $post = $this->next_post();! setup_postdata($post);! }! ! }   10   10
  • 11. Next: Debugging! <?php! require "../../global_setting.php";! include "../../custom/functions.php" ;! ! $someId = 1337;! $sql = "INSERT INTO some_table (`name`, `date`, `count`) ";! $sql .= "VALUES ('{$someId}', " . time() - mktime(0,0,0) . " , 6)";! ! // echo '$sql: '; ! // var_dump($sql);! // die();! ! Die  Debug-­‐Ausgabe  wäre  übrigens  $sql:  string(16)  "-­‐1322434800  ,  6)"   11   11
  • 12. Schwache, dynamische Typisierung echo (true == "false");! => 1! echo (true === "false");! => ! echo (true == "");! => ! ! echo (10 + 012);! => 20! echo (10 + 09);! => 10! ! echo 010 + 5;! => 13! echo "010" + 5;! => 15! ! 12   12
  • 13. World Wide Web 13   13
  • 14. Twitter JSON API {! "completed_in":0.209,! "max_id":141283786544513025,! "max_id_str":"141283786544513025",! "next_page":"?page=2&max_id=141283786544513025&q=php%20sucks&rpp=1",! "page":1,! "query":"php+sucks",! "refresh_url":"?since_id=141283786544513025&q=php%20sucks",! "results":[{"created_at":"Mon,! 28 Nov 2011 22:34:14 +0000",! "from_user":"infomancien",! "from_user_id":79284740,! "from_user_id_str":"79284740",! "from_user_name":"Infomancien",! "geo":null,! "id":141283786544513025,! "id_str":"141283786544513025",! "iso_language_code":"en",! "metadata":{"result_type":"recent"},! "profile_image_url":"http://a3.twimg.com/[...]/alicelascombe_normal.png",! "source":"&lt;a href=&quot;http://www.hootsuite.com[...]",! "text":"(@rww) Entrepreneurship Sucks - The sad state of affairs is that working ! for yourself is really just a worse version... http://t.co/BEctTyFw",! "to_user":null,! "to_user_id":null,! "to_user_id_str":null,! "to_user_name":null}],! "results_per_page":1,! "since_id":0,! "since_id_str":"0"! }! 14   14
  • 16. Vom Prototyp zum Produkt ??? 16   16
  • 17. Das finale Produkt mit echter Technologien umsetzen §  Enterprise-Grade Application Server §  Spring §  Java Server Faces §  Hibernate §  Junit 17   17
  • 18. PHP ist (uns) bereits bekannt. 18  
  • 19. Application Server §  Ein beliebiger Webserver §  Schmaler Footprint •  PokerStrategy.com: maximal 8MB je Request •  JBoss + Liferay: 1,2 GB für Bootstrapping 19   19
  • 20. Application Server / Skalierung über FPM 20   20
  • 21. Spring / Java Server Faces •  Weit verbreitet •  100% OOP •  Beeindruckender Umfang •  Lose gekoppelt - PDF- Handling •  Annotations - Social Media Connectoren •  Dependency Injection 21   21
  • 22. Hibernate / JUnit DBAL  /  ORM  für   Dynamic  Mocks   -­‐  MySQL   -­‐  SQLite   -­‐  PostgreSQL   -­‐  MSSQL   -­‐  Oracle     ODM  für   -­‐  CouchDB   -­‐  MongoDB   -­‐  PHPCR   22   22
  • 23. Nicht nur das PHP-Ökosystem rockt. 23  
  • 24. PHP arbeitet wie das WWW §  ... ist Request-Basiert §  ... hat keine strikte Typisierung 24   24
  • 25. Batteries included §  XML, Image/Audio-Manipulation, Zip-Files, OAuth, Cryptography §  mächtige String- und Array-Funktionen §  Reflection §  PECL/Pear USE   IMPORT   DLLs   25   25
  • 26. Auch das ist PHP §  Autoloading §  Namespacing §  Type Hinting §  Anonyme Funktionen §  Abstrakte Klassen §  Interfaces §  private, protected, public, final §  Exceptions 26   26
  • 27. Sprache oder Entwickler – Wer suckt denn nun? Mit  PHP  kann  man  viel  erreichen   Es  ist  sehr  wichWg,  gute  Entwickler  zu  haben   27   27
  • 29. PokerStrategy.com in Zahlen §  70 Mio Seitenabrufe / Monat 7%   7%   8%   §  6 Mio Reg. User §  500.000 LOC 14%   3%   4%   3%   §  >50 TB Traffic / Monat §  19 Sprachen 6%   4%   Rest  of  the  world:   §  Insgesamt ~50 Server •  2 Load Balancer •  10 App-Server 3%   41%   •  15 DB-Server •  Video Delivery, Community, ... 29   29
  • 30. Case Study: ID-Check CASE STUDY §  Problem: Fraud §  Validierung des Nutzers notwendig §  Upload von Dokumenten 30   30
  • 31. ID-Check: Screenshot CASE STUDY 31   31
  • 32. ID-Check: Requirements §  Privacy CASE STUDY •  Nur Thumbnail nach extern ausliefern •  nur an den Uploader §  Performance •  Uploads (bis 20MB JPEG) in 2 Größen umrechnen •  Erwartete Last: -  Max. 10.000 Bilder / Tag -  Max. 4.000 Bilder / Stunde §  Security •  Lastkontrolle / Missbrauch verhindern •  Viren-Check §  Funktional •  Thumbnail für User •  Preview in mittlerer Größe 32   32
  • 33. ID-Check: Basic Setup CASE STUDY ID-Check Server API HTTP HTTP AJAX Proxy Backoffice Frontend 33   33
  • 34. ID-Check: XSRF-Protection CASE STUDY ID-Check Server Validate Datenbank Token API Create HTTP HTTP Token AJAX Proxy Backoffice Frontend 34   34
  • 35. Uploads von nicht angemeldeten Usern verhindern CASE STUDY Check SSO Service Login State ID-Check Server Validate Datenbank Token API Check Login State Create HTTP HTTP Token AJAX Proxy Backoffice Frontend 35   35
  • 36. ID-Check: Performance / Skalierung CASE STUDY §  4 Worker / 4 Kerne §  Synchroner Prozess für Anti-Virus und Thumbnail §  Asynchron für mittlere Größe 36   36
  • 37. ID-Check: Fazit CASE STUDY §  Entwicklungszeit: 8 Wochen §  Server virtualisiert ohne Last-Probleme 37   37
  • 38. „PHP-Entwickler sind aber @!#*$“ 38  
  • 39. Auch / Gerade bei PHP: Maximale Qualitätsstandards §  Nur exzellente Entwickler einstellen §  Continuous Improvement •  Konferenzen, Zertifizierungen, Schulungen, Pair Programming, ... §  Continuous Integration (Jenkins) •  Code Sniffer, Mess Detection •  Coding Standards, Unit-Tests §  Regelmäßige Code – Reviews §  ... 39   39
  • 40. Roundup §  Man kann in jeder Sprache Schrott machen §  Der Entwickler macht den Unterschied §  Die gewählte Architektur ist wichtiger als die gewählte Sprache §  Für ICANS ist PHP auch langfristig die richtige Entscheidung 40   40
  • 42. ICANS GmbH Valentinskamp 18 20354 Hamburg Germany Phone: +49 40 22 63 82 9-0 Fax: +49 40 38 67 15 92 Web: www.icans-gmbh.com   42