Your SlideShare is downloading. ×
0
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

2012 coscup - Build your PHP application on Heroku

7,626

Published on

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,626
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Build your PHP application on Heroku Ronny Wang @ PIXNET
  • 2. PaaSPlatform-as-a-Service 1
  • 3. Deploy… And Run! 2
  • 4. Install…Config…Linux? FreeBSD? Debian? Ubuntu?RPM? Ports? Package? Apt? yum? Apache? Nginx? PHP-cgi? FastCGI? PHP-Fpm? 3
  • 5. Herokuher-OH-koo 4
  • 6. 2007 ~ 5
  • 7. Amazon Web Service US-east-1 ~200ms latency 6
  • 8. Lots of Addons 7
  • 9. Easy scale 8
  • 10. PostgreSQL 9
  • 11. Free!!!On a small scale… 10
  • 12. What’s Stack?Aspen, Bamboo, Cedar 11
  • 13. Stack CedarClojure Facebook Java Spring or Play Node.js Python or Django Ruby or Rails Scala 12
  • 14. No PHP? 13
  • 15. Facebook and Herokuhttp://blog.heroku.com/archives/2011/9/15/facebook/ 14
  • 16. What’s Dyno? 15
  • 17. Web, worker, cron, run process All are dynos 16
  • 18. 0.05US$/hour/dyno= 1000NT$/month/dyno 17
  • 19. 750hours free! 18
  • 20. Heroku toolbelthttps://toolbelt.heroku.comHeroku Client, Foreman, Git 19
  • 21. First: heroku login 20
  • 22. heroku create# heroku createCreating evening-earth-7959... done, stack is cedarhttp://evening-earth-7959.herokuapp.com/ |git@heroku.com:evening-earth-7959.gitGit remote heroku added 21
  • 23. Add index.php<?phpecho Hello World; 22
  • 24. git commit index.php –m ‘add Hello World’ 23
  • 25. git pushCounting objects: 3, done.Writing objects: 100% (3/3), 250bytes, done.Total 3 (delta 0), reused 0(delta 0)-----> Heroku receiving push-----> PHP app detected-----> Bundling Apache 2.2.12-----> Bundling PHP 5.3.10-----> Discovering process typesProcfile declares types -> (none)Default types for PHP -> web-----> Compiled slug size in 21.5MB-----> Launching... done, v3http://evening-earth-7959.herokuapp.com deployed toHeroku 24
  • 26. 25
  • 27. heroku logs2012-08-16T10:59:15+00:00 app[web.1]: [Thu Aug 16 10:59:15 2012] [notice]Apache/2.2.22 (Unix) PHP/5.3.10 configured -- resuming normal operations2012-08-16T10:59:16+00:00 app[web.1]: [Thu Aug 16 10:59:16 2012] [error]server reached MaxClients setting, consider raising the MaxClients setting2012-08-16T11:03:16+00:00 app[web.1]: 10.189.119.194 - -[16/Aug/2012:11:03:15 +0000] "GET / HTTP/1.1" 200 142012-08-16T11:03:16+00:00 app[web.1]: 10.217.59.175 - -[16/Aug/2012:11:03:15 +0000] "GET /favicon.ico HTTP/1.1" 200 1025 26
  • 28. Database: PostgreSQLhttps://postgres.heroku.com/ 27
  • 29. Starter databasesDevPlan Free 10K rowsBasicPlan $9/month 10M rows 28
  • 30. Production databases Size: up to 1TB Crane 400MB Cache $50/monthKappa 800MB Cache $100/month : :Baku 34GB Cache $3200/monthMecha 68GB Cache $6400/month 29
  • 31. heroku config> heroku configDATABASE_URL: postgres://foofoofoo:barbarbar@ec2-123-123-123-123.compute-1.amazonaws.com/foofoofooSHARED_DATABASE_URL: postgres://foofoofoo:barbarbar@ec2-123-123-123-123.compute-1.amazonaws.com/foofoofoo 30
  • 32. if (!getenv(DATABASE_URL)) { die(Need DATABASE_URL);}if (!preg_match(‘#postgres://([^:]*):([^@]*)@([^/:]*)(:d+)?/(.*)#’,strval(getenv(DATABASE_URL)), $matches)) { die(Unknown DATABASE_URL);}$user = $matches[1];$pass = $matches[2];$host = $matches[3];$port = ltrim($matches[4], :) ?: 1486;$dbname = $matches[5];$dbconn = pg_connect("host={$host} port={$port} dbname={$dbname}user={$user} password=${pass} sslmode=require options=--client_encoding=UTF8") or die(Could not connect: . pg_last_error());pg_execute($dbconn, "SELECT * FROM table");#https://github.com/pixnet/pixframework-heroku/blob/master/init.inc.php 31
  • 33. heroku runStart a dyno and run command 32
  • 34. heroku config:set LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib 33
  • 35. heroku run "~/bin/php ~/www/script.php" 34
  • 36. Heroku Scheduler Schedule your task 35
  • 37. Daily, hourly, 10 minutes 36
  • 38. 37
  • 39. $ ~/bin/php ~/www/cron.php 38
  • 40. Heroku worker 39
  • 41. File: Procfileworker: ~/bin/php ~/www/worker.php 40
  • 42. heroku ps:scale worker=N 41
  • 43. heroku ps# heroku ps=== web: `sh boot.sh`web.1: starting for 4s=== worker: `~/bin/php ~/www/test.php`worker.1: up for 25s# 42
  • 44. heroku logs –p worker -t# heroku logs –p worker –t2012-08-14T08:21:29+00:00 heroku[worker.1]: State changed from up to down2012-08-14T08:21:31+00:00 heroku[worker.1]: Stopping all processes withSIGTERM2012-08-14T08:21:33+00:00 heroku[worker.1]: Process exited with status 1432012-08-16T10:58:48+00:00 heroku[worker.1]: Starting process with command`while true; do ~/bin/php ~/www/test.php; sleep 1; done`2012-08-16T10:58:49+00:00 heroku[worker.1]: State changed from starting toup 43
  • 45. • Procfileworker: while true; do ~/bin/php ~/www/worker.phpsleep 1; donehttps://github.com/pixnet/pixframework-heroku/blob/master/Procfile 44
  • 46. Addons – Custom domain xxxxx.herokuapp.com 45
  • 47. $ heroku domains:add www.example.com 46
  • 48. Addons - Memcache 47
  • 49. Memcache with SASL 48
  • 50. 49
  • 51. heroku config> heroku configMEMCACHE_PASSWORD => *********MEMCACHE_SERVERS => mc6.ec2.northscale.netMEMCACHE_USERNAME => app******%40heroku.com 50
  • 52. https://github.com/ronnywang/PHPMemcacheSASLinclude(MemcacheSASL.php);$m = new MemcacheSASL;$m->addServer(getenv(MEMCACHE_SERVERS), 11211);$m->setSaslAuthData(getenv(MEMCACHE_USERNAME),getenv(MEMCACHE_PASSWORD));var_dump($m->add(test, 123));$m->delete(test); 51
  • 53. Pix Framework on Heroku http://framework.pixnet.net/http://github.com/pixnet/pixframewrok 52
  • 54. http://github.com/pixnet/pixframework-heroku• Core – /init.inc.php – /.gitignore – /libs/pixframework/ – /models/• Web – /.htaccess – /index.php – /controllers/ – /views/• Worker/Cron/Script – /prompt.php – /cron.php – /worker.php – /Procfile 53
  • 55. Create table# heroku run “~/bin/php ~/www/prompt”Running `~/bin/php ~/www/prompt.php` attached to terminal... up, run.1>> User::createTable()>> exit# 54
  • 56. Q&A We are hiring!techjob@pixnet.tw 55

×