php: un progetto open source cresciuto insieme al web
DESCRIPTION
PHP, i cambiamenti di un progetto cresciuto insieme al webTRANSCRIPT
![Page 1: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/1.jpg)
Un progetto open source cresciuto insieme al web
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 2: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/2.jpg)
Asmir Mustafic◦ PHP: 8+ anni
◦ Lavoro @
◦ PUG Friuli
◦ http://linkedin.com/in/goetas
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 3: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/3.jpg)
Su le mani!
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 4: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/4.jpg)
Linguaggio di scripting (1995)◦ Interpretato
Orientato al web
Open source (PHP License [non GPL])
Popolare, scalabile, facile, ecc.
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 5: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/5.jpg)
Quanto è cambiato il nostro mondo negli ultimi 10 anni, con l’avvento del era di internet?
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 6: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/6.jpg)
Wordpress
PHP
10M di download
61M di blog attivi
http://wordpress.com
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 7: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/7.jpg)
MediaWiki
PHP
Opensource
Multidatabase
Usato da Wikipedia
http://www.mediawiki.org
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 8: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/8.jpg)
Search engine & more
PHP
Migrato da C/C++ a PHP nel 2002
3.4 G pageview/day
Uno dei leader del web attuale
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 9: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/9.jpg)
Social network
PHP (hiphop)
800M di utenti
10K server
http://facebook.com
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 10: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/10.jpg)
Ricerca campione su 10M domini◦ 59% usa PHP
40 dei 100 siti più vistati al mondo usa PHP
6° posto dei linguaggi più popolari in assoluto (TIOBE Index Settembre 2011)
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 11: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/11.jpg)
Perché dovrei scegliere PHP per il mio prossimo progetto?
Cosa ha di buono?
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 12: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/12.jpg)
Asmir Mustafic - Linux Day 2011 Pordenone
Open source
Community
Documentato
Facile
Completo &
Maturo
Estensibile
Veloce &
Scalabile
Deployment
rapido
![Page 13: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/13.jpg)
“Si usa Java o .NET per fare i siti seri!”
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 14: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/14.jpg)
Uso Storia
1994◦ Esperimenti per
appassionati 1998
◦ Siti personali 2002
◦ Semplici siti e mini portali◦ Blog e CMS
2008◦ Grandi siti◦ Istituzioni◦ Multinazionali
Asmir Mustafic - Linux Day 2011 Pordenone
Enterprise
Small
Home
![Page 15: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/15.jpg)
Si possono produrre pessime applicazioni anche con ottimi linguaggi.
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 16: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/16.jpg)
Vediamo tre semplici regole...
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 17: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/17.jpg)
Pensare molto bene, prima di iniziare a scrivere codice
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 18: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/18.jpg)
Troverete la soluzione migliore
Risolvere un problema in fase di progettazione costa davvero poco
In produzione
In fase di sviluppo
In fase di progettazione
Ore di lavro
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 19: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/19.jpg)
Non reinventare la ruota
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 20: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/20.jpg)
Problematiche già risolte◦ Da molto tempo (soluzioni mature)
◦ Nel migliore dei modi
◦ Da molte persone (anche da esperti del problema)
Risparmi tempo e fatica
Ma se siete davvero sicuri di voi stessi, allora si può provare...
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 21: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/21.jpg)
Non essere rigidi
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 22: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/22.jpg)
Non avrete tempo
Non avrete voglia
Vorrete provare (bene o male che vada, imparerete qualcosa!)
Dovrete migliorare la ruota
Se non si cambia, non si migliora, si perde in partenza!
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 23: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/23.jpg)
Le “regole” sono tante altre…#tu, #cliente, #capo, #team, #specifiche, ecc.
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 24: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/24.jpg)
Alcune “best practice” per semplificare la vita...
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 25: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/25.jpg)
Aderite agli standard◦ Aumenti la qualità
Richiedere gli standard
Asmir Mustafic - Linux Day 2011 Pordenone
Regola #2Non reinventare la ruota
Standard
Soluzioni
(architetturali)Formattazione Consistenza Strumenti
Filesystem
(nomenclatura)
Faciliti la collaborazione
![Page 26: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/26.jpg)
Commenti sul codice ◦ phpDocumentor
◦ PEAR UML (consigliato)
Schemi e Diagrammi◦ UML, ER, Wireframe, Workflow...
Usate un wiki aziendale o DocBook...
Usate un sistema di controllo versione
Regola #1Pensare molto bene prima di iniziare a scrivere codice
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 27: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/27.jpg)
Centralizzato (SVN) Distribuito (GIT)
Server centrale
Si lavora su copie locali
Migliore controllo accessi
Più repository “principali”
Si inviano le modifiche ai propri “peer”
Si sfuma il concetto di copia locale
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 28: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/28.jpg)
Dividete in entità ben distinte:◦ Dati (Model)
◦ Visualizzazione (View)
◦ Elaborazione (Controller)
Ogni classe/file/funzione assolve ad un solo compito (Single Responsibility Principle)!
La maggior parte delle moderne applicazioni ereditano qualche principio da MVC.
Controller
ViewModel
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 29: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/29.jpg)
<?php
$res = mysql_query("SELECT * FROM utenti");
?>
<select name='utente'>
<?php
while($data = mysql_fetch_array($res)){
echo "<option
value='".$data["id"]."' " .($sel==$data["id"]?'selected':'').">";
echo htmspecialchars($data["nome"],ENT_QUOTES,'UTF-8');
echo "</option>";
}
echo "</select>";
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 30: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/30.jpg)
<?php
$res = mysql_query("SELECT * FROM utenti");
?>
<select name='utente'>
<?php
while($data = mysql_fetch_array($res)){
echo "<option
value='".$data["id"]."' " .($sel==$data["id"]?'selected':'').">";
echo htmspecialchars($data["nome"],ENT_QUOTES,'UTF-8');
echo "</option>";
}
echo "</select>";
DATI
PRESENTAZIONE
SICUREZZA
LOGICA
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 31: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/31.jpg)
Basta con codice “groviglio”!
Applicate i principi dell’MVC!
<?php
$res = mysql_query("SELECT * FROM utenti");
?>
<select name='utente'>
<?php
while($data = mysql_fetch_array($res)){
echo "<option
value='".$data["id"]."' " .($sel==$data["id"]?'selected':'').">";
echo htmspecialchars($data["nome"],ENT_QUOTES,'UTF-8');
echo "</option>";
}
echo "</select>";
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 32: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/32.jpg)
<?php
$utenti = getElencoUtenti();
display("utenti.template", array("utenti"=>$utenti, "sel"=>$selected));
Asmir Mustafic - Linux Day 2011 Pordenone
<?php
function getElencoUtenti(){
$res = mysql_query("SELECT * FROM utenti");
return mysql_fetch_all($res) ;
}
Controller
View
Model
<select name='name'>
<? foreach($utenti as $ut): ?>
<option <?= selectedIf($ut['id']==$sel)?>><?= escape($ut['nome']) ?>
</option>
<? endforeach ?>
</select>
![Page 33: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/33.jpg)
<?php
function getElencoUtenti(){
$res = mysql_query("SELECT * FROM utenti");
return mysql_fetch_all($res) ;
}
Controller
Model
<?php
$utenti = getElencoUtenti();
display("utenti.template", array("utenti"=>$utenti, "sel"=>$selected));
Asmir Mustafic - Linux Day 2011 Pordenone
Dati prelevati dal Model
View
<select name='name'>
<? foreach($utenti as $ut): ?>
<option <?= selectedIf($ut['id']==$sel)?>><?= escape($ut['nome']) ?>
</option>
<? endforeach ?>
</select>
![Page 34: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/34.jpg)
<?php
$utenti = getElencoUtenti();
display("utenti.template", array("utenti"=>$utenti, "sel"=>$selected));
<?php
function getElencoUtenti(){
$res = mysql_query("SELECT * FROM utenti");
return mysql_fetch_all($res) ;
}
Controller
View
Model
<select name='name'>
<? foreach($utenti as $ut): ?>
<option <?= selectedIf($ut['id']==$sel)?>><?= escape($ut['nome']) ?>
</option>
<? endforeach ?>
</select>
Asmir Mustafic - Linux Day 2011 Pordenone
Dati visualizzati tramite la Vista
![Page 35: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/35.jpg)
Database driver ORM
PHP PDO
Doctrine DBAL
Creole
ADODB
Doctrine 2 Propel dORM
Asmir Mustafic - Linux Day 2011 Pordenone
Regola #2Non reinventare la ruotaModel per MVC
$user = new User();
$user->setName('name');
$orm->persist($user); // save
$user = $orm->findByName('name');
$orm->remove($user); // delete
![Page 36: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/36.jpg)
Classico XML Attribute Template
Twig
Smarty
Dwoo
ATal PHPTAL Open Power Template
{if count($utenti)}
<ul>
{foreach from=$utenti item=ut}
<li>
{$ut->name|escape}
</li>
{/foreach}
</ul>
{/if}
<ul t:if="count($utenti)">
<li t:foreach="$utenti as $ut">
{$ut->name}
</li>
</ul>
Asmir Mustafic - Linux Day 2011 Pordenone
View per MVC
![Page 37: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/37.jpg)
Probabilmente◦ Penserete meglio a ciò che fate (Regola #1)◦ Non reinventerete la ruota (Regola #2)◦ Sarete aperti al cambiamento (Regola #3)◦ Applicherete MVC
Probabilmente◦ Il risultato sarà più standard◦ Userete un Template Engine◦ Userete un ORM◦ Sfrutterete gli strumenti offerti (se fanno al caso vostro)◦ L’applicazione sarà più sicura◦ ecc.
Otterrete migliori risultati con meno sforzo!
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 38: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/38.jpg)
Non esiste il framework migliore
Non esiste il framework peggiore
Esiste il framework più adatto!
Scegliete il vostro◦ Orizzontale? Verticale?
◦ PHP4? 5? 5.3+?
◦ ecc.
Asmir Mustafic - Linux Day 2011 Pordenone
Zend Framework, Symfony, Kohana, eZComponents, Yii,, CakePHP, Lithium, Code Igniter e troppi altri!
![Page 39: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/39.jpg)
Scrivete i test◦ Applicate modifiche senza il terrore di “rompere”
l’applicazione◦ PHPUnit (standard de facto)
Pensate sempre alla sicurezza
Tenete sotto controllo le prestazioni
Usate un IDE “serio”◦ Eclipse, Zend Studio, Aptana, NetBeans, Komodo
Usate un debugger◦ Xdebug, Zend Debugger
Provate◦ Phing, Jenkins, Redmine
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 40: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/40.jpg)
Uno dei modi migliori per mantenersi aggiornati e al passo con i tempi è partecipare al mondo open source.
Asmir Mustafic - Linux Day 2011 Pordenone
![Page 41: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/41.jpg)
Asmir Mustafic - Linux Day 2011 Pordenone
Domande?
![Page 42: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/42.jpg)
PHP http://php.net
Zend Framework http://framework.zend.com
Symfony http://symfony.com
eZComponents http://ezcomponents.orghttp://incubator.apache.org/zetacomponents/
CakePHP http://cakephp.org/
Twig http://twig-project.com
ATal http://opensource.mercuriosistemi.com
Dwoo http://dwoo.com
Smarty http://smarty.net
OpenPowerTemplate http://www.invenzzia.org
Subversion http://subversion.apache.org
GIT http://git-scm.com
PHPUnit http://phpunit.de
SipleTest http://www.simpletest.org/
Doctrine http://www.doctrine-project.org/
dOrm http://getdorm.com
Propel http://www.propelorm.org/
Pear http://pear.php.net
phpDocumentor http://www.phpdoc.org/
Phing http://www.phing.info
Jenkins http://jenkins-ci.com
Redmine http://redmine.com
Asmir Mustafic - Linux Day 2011 Pordenone
Yii http://www.yiiframework.com/
Lithium http://lithify.me/
Kohana http://kohanaframework.org/
Eclipse http://www.eclipse.org
Zend Studio http://www.zend.com/products/studio
Net beans http://netbeans.org/
Komodo http://www.activestate.com/komodo-ide
Aptana http://www.aptana.com/
Xdebug http://xdebug.org/
![Page 43: PHP: Un progetto open source cresciuto insieme al web](https://reader034.vdocuments.pub/reader034/viewer/2022052623/5599764d1a28ab74468b4608/html5/thumbnails/43.jpg)
php.net phpadvent.com rogchap.com www.slideshare.net/weppos wikipedia.com zend.com langpop.com wordpress.com www.slideshare.net/dlondero joind.in/talk/view/65
Asmir Mustafic - Linux Day 2011 Pordenone