php sucks?!
DESCRIPTION
TRANSCRIPT
1
PHP Sucks?! Simon Neidhold, Stefan Wiegreffe, ICANS GmbH www.icans-gmbh.com
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
3 3
PHP sucks?!
4 4
Die Nadel im Heuhaufen
5 5
to, _to_, 2
6 6
Unterm Strich zählt die Semantik
7 7
Next: Wordpress
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; ?> !! [...] !
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:
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:
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)"
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!!
13 13
World Wide Web
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":"<a href="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
15 15
(Rapid) Prototyping FTW!
16 16
Vom Prototyp zum Produkt
???
17 17
Das finale Produkt mit echter Technologien umsetzen
§ Enterprise-Grade Application Server
§ Spring
§ Java Server Faces
§ Hibernate
§ Junit
18
PHP ist (uns) bereits bekannt.
19 19
Application Server
§ Ein beliebiger Webserver
§ Schmaler Footprint
• PokerStrategy.com: maximal 8MB je Request
• JBoss + Liferay: 1,2 GB für Bootstrapping
20 20
Application Server / Skalierung über FPM
21 21
Spring / Java Server Faces
• Weit verbreitet • Beeindruckender Umfang
- PDF- Handling - Social Media Connectoren
• 100% OOP • Lose gekoppelt • Annotations • Dependency Injection
22 22
Hibernate / JUnit
DBAL / ORM für -‐ MySQL -‐ SQLite -‐ PostgreSQL -‐ MSSQL -‐ Oracle ODM für -‐ CouchDB -‐ MongoDB -‐ PHPCR
Dynamic Mocks
23
Nicht nur das PHP-Ökosystem rockt.
24 24
PHP arbeitet wie das WWW
§ ... ist Request-Basiert
§ ... hat keine strikte Typisierung
25 25
Batteries included
§ XML, Image/Audio-Manipulation, Zip-Files, OAuth, Cryptography
§ mächtige String- und Array-Funktionen
§ Reflection
§ PECL/Pear
USE DLLs IMPORT
26 26
Auch das ist PHP
§ Autoloading
§ Namespacing
§ Type Hinting
§ Anonyme Funktionen
§ Abstrakte Klassen
§ Interfaces
§ private, protected, public, final
§ Exceptions
27 27
Sprache oder Entwickler – Wer suckt denn nun?
Mit PHP kann man viel erreichen
Es ist sehr wichWg, gute Entwickler zu haben
28 28
Erfolgreich mit PHP
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%
30 30
Case Study: ID-Check
§ Problem: Fraud
§ Validierung des Nutzers notwendig
§ Upload von Dokumenten
CASE STUDY
31 31
ID-Check: Screenshot
CASE STUDY
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
33 33
ID-Check: Basic Setup
ID-Check Server
API
BackofficeFrontend
AJAX Proxy
HTTP HTTP
CASE STUDY
34 34
ID-Check: XSRF-Protection
ID-Check Server
API
BackofficeFrontend
AJAX Proxy
Datenbank
CreateToken
ValidateToken
HTTP HTTP
CASE STUDY
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
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
37 37
ID-Check: Fazit
§ Entwicklungszeit: 8 Wochen
§ Server virtualisiert ohne Last-Probleme
CASE STUDY
38
„PHP-Entwickler sind aber @!#*$“
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
§ ...
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
41
www.icans-‐gmbh.com
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