More Related Content Similar to 2012 coscup - Build your PHP application on Heroku Similar to 2012 coscup - Build your PHP application on Heroku (20) 2012 coscup - Build your PHP application on Heroku22. heroku create
# heroku create
Creating evening-earth-7959... done, stack is cedar
http://evening-earth-7959.herokuapp.com/ |
git@heroku.com:evening-earth-7959.git
Git remote heroku added
21
25. git push
Counting 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 types
Procfile declares types -> (none)
Default types for PHP -> web
-----> Compiled slug size in 21.5MB
-----> Launching... done, v3
http://evening-earth-7959.herokuapp.com deployed to
Heroku 24
27. heroku logs
2012-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 operations
2012-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 setting
2012-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 14
2012-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
30. Production databases
Size: up to 1TB
Crane 400MB Cache $50/month
Kappa 800MB Cache $100/month
: :
Baku 34GB Cache $3200/month
Mecha 68GB Cache $6400/month
29
31. heroku config
> heroku config
DATABASE_URL: postgres://foofoofoo:barbarbar@ec2-123-123-123-
123.compute-1.amazonaws.com/foofoofoo
SHARED_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
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 –t
2012-08-14T08:21:29+00:00 heroku[worker.1]: State changed from up to down
2012-08-14T08:21:31+00:00 heroku[worker.1]: Stopping all processes with
SIGTERM
2012-08-14T08:21:33+00:00 heroku[worker.1]: Process exited with status 143
2012-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 to
up
43
45. • Procfile
worker: while true; do ~/bin/php ~/www/worker.php
sleep 1; done
https://github.com/pixnet/pixframework-
heroku/blob/master/Procfile
44
51. heroku config
> heroku config
MEMCACHE_PASSWORD => *********
MEMCACHE_SERVERS => mc6.ec2.northscale.net
MEMCACHE_USERNAME => app******%40heroku.com
50
53. Pix Framework on Heroku
http://framework.pixnet.net/
http://github.com/pixnet/pixframewrok
52
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