php sucks?!

42
PHP Sucks?! Simon Neidhold, Stefan Wiegreffe, ICANS GmbH www.icans-gmbh.com

Upload: icans-gmbh

Post on 28-Nov-2014

23.467 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: PHP Sucks?!

1  

PHP Sucks?! Simon Neidhold, Stefan Wiegreffe, ICANS GmbH www.icans-gmbh.com

Page 2: PHP Sucks?!

2  2

Über uns

Simon  Neidhold  So&ware  Engineer  simon.neidhold@icans-­‐gmbh.com  @sneidhold  

Stefan  Wiegreffe  Team  Lead  Web  Development  stefan.wiegreffe@icans-­‐gmbh.com  @swiegreffe  

Page 3: PHP Sucks?!

3  3

PHP sucks?!

Page 4: PHP Sucks?!

4  4

Die Nadel im Heuhaufen

Page 5: PHP Sucks?!

5  5

to, _to_, 2

Page 6: PHP Sucks?!

6  6

Unterm Strich zählt die Semantik

Page 7: PHP Sucks?!

7  7

Next: Wordpress

Page 8: PHP Sucks?!

8  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; ?> !! [...] !

Page 9: PHP Sucks?!

9  9

the_post()

/** ! * 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(); !} !

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

Page 10: PHP Sucks?!

10  10

WTF??

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); ! } !!}  

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

Page 11: PHP Sucks?!

11  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)"  

Page 12: PHP Sucks?!

12  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!!

Page 13: PHP Sucks?!

13  13

World Wide Web

Page 14: PHP Sucks?!

14  14

{ ! "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"!} !

Twitter JSON API

Page 15: PHP Sucks?!

15  15

(Rapid) Prototyping FTW!

Page 16: PHP Sucks?!

16  16

Vom Prototyp zum Produkt

???

Page 17: PHP Sucks?!

17  17

Das finale Produkt mit echter Technologien umsetzen

§ Enterprise-Grade Application Server

§ Spring

§ Java Server Faces

§ Hibernate

§ Junit

Page 18: PHP Sucks?!

18  

PHP ist (uns) bereits bekannt.

Page 19: PHP Sucks?!

19  19

Application Server

§ Ein beliebiger Webserver

§ Schmaler Footprint

•  PokerStrategy.com: maximal 8MB je Request

•  JBoss + Liferay: 1,2 GB für Bootstrapping

Page 20: PHP Sucks?!

20  20

Application Server / Skalierung über FPM

Page 21: PHP Sucks?!

21  21

Spring / Java Server Faces

• Weit verbreitet •  Beeindruckender Umfang

- PDF- Handling - Social Media Connectoren

•  100% OOP •  Lose gekoppelt •  Annotations •  Dependency Injection

Page 22: PHP Sucks?!

22  22

Hibernate / JUnit

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

Dynamic  Mocks  

Page 23: PHP Sucks?!

23  

Nicht nur das PHP-Ökosystem rockt.

Page 24: PHP Sucks?!

24  24

PHP arbeitet wie das WWW

§  ... ist Request-Basiert

§  ... hat keine strikte Typisierung

Page 25: PHP Sucks?!

25  25

Batteries included

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

§ mächtige String- und Array-Funktionen

§ Reflection

§ PECL/Pear

USE   DLLs  IMPORT  

Page 26: PHP Sucks?!

26  26

Auch das ist PHP

§ Autoloading

§ Namespacing

§ Type Hinting

§ Anonyme Funktionen

§ Abstrakte Klassen

§  Interfaces

§ private, protected, public, final

§ Exceptions

Page 27: PHP Sucks?!

27  27

Sprache oder Entwickler – Wer suckt denn nun?

Mit  PHP  kann  man  viel  erreichen  

Es  ist  sehr  wichWg,  gute  Entwickler  zu  haben  

Page 28: PHP Sucks?!

28  28

Erfolgreich mit PHP

Page 29: PHP Sucks?!

29  29

PokerStrategy.com in Zahlen

§ 70 Mio Seitenabrufe / Monat

§ 6 Mio Reg. User

§ 500.000 LOC

§ >50 TB Traffic / Monat

§ 19 Sprachen

§  Insgesamt ~50 Server •  2 Load Balancer

•  10 App-Server

•  15 DB-Server

•  Video Delivery, Community, ...

14%  

8%  7%  7%  

4%  

6%  

4%  

3%  

3%  3%  

Rest  of  the  world:  

41%  

Page 30: PHP Sucks?!

30  30

Case Study: ID-Check

§ Problem: Fraud

§ Validierung des Nutzers notwendig

§ Upload von Dokumenten

CASE STUDY

Page 31: PHP Sucks?!

31  31

ID-Check: Screenshot

CASE STUDY

Page 32: PHP Sucks?!

32  32

ID-Check: Requirements

§ Privacy •  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

CASE STUDY

Page 33: PHP Sucks?!

33  33

ID-Check: Basic Setup

ID-Check Server

API

BackofficeFrontend

AJAX Proxy

HTTP HTTP

CASE STUDY

Page 34: PHP Sucks?!

34  34

ID-Check: XSRF-Protection

ID-Check Server

API

BackofficeFrontend

AJAX Proxy

Datenbank

CreateToken

ValidateToken

HTTP HTTP

CASE STUDY

Page 35: PHP Sucks?!

35  35

Uploads von nicht angemeldeten Usern verhindern

ID-Check Server

API

BackofficeFrontend

AJAX Proxy

SSO Service

Datenbank

CreateToken

ValidateToken

HTTP HTTP

CheckLoginState

CheckLoginState

CASE STUDY

Page 36: PHP Sucks?!

36  36

ID-Check: Performance / Skalierung

§ 4 Worker / 4 Kerne

§ Synchroner Prozess für Anti-Virus und Thumbnail

§ Asynchron für mittlere Größe

CASE STUDY

Page 37: PHP Sucks?!

37  37

ID-Check: Fazit

§ Entwicklungszeit: 8 Wochen

§ Server virtualisiert ohne Last-Probleme

CASE STUDY

Page 38: PHP Sucks?!

38  

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

Page 39: PHP Sucks?!

39  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

§  ...

Page 40: PHP Sucks?!

40  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

Page 41: PHP Sucks?!

41  

www.icans-­‐gmbh.com  

Page 42: PHP Sucks?!

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