Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Command Line PHP Basics
Search
Jason Lotito
January 21, 2013
Technology
1
58
Command Line PHP Basics
Jason Lotito
January 21, 2013
Tweet
Share
More Decks by Jason Lotito
See All by Jason Lotito
tmux
jasonlotito
1
42
Getting Things Done from Someone with OCD & ADHD
jasonlotito
0
87
How We Killed Our Process, Technology Stack, and Assumptions — and Survived
jasonlotito
0
48
Twitter Bootstrap, or why being a PHP Developer is a bad idea.
jasonlotito
2
560
require.js
jasonlotito
3
93
tmux
jasonlotito
0
130
Other Decks in Technology
See All in Technology
Agentic Workflowという選択肢を考える
tkikuchi1002
1
430
本当に使える?AutoUpgrade の新機能を実践検証してみた
oracle4engineer
PRO
1
130
TechLION vol.41~MySQLユーザ会のほうから来ました / techlion41_mysql
sakaik
0
160
新卒3年目の後悔〜機械学習モデルジョブの運用を頑張った話〜
kameitomohiro
0
400
AIの最新技術&テーマをつまんで紹介&フリートークするシリーズ #1 量子機械学習の入門
tkhresk
0
130
UIテスト自動化サポート- Testbed for XCUIAutomation practice
notoroid
0
120
AIのAIによるAIのための出力評価と改善
chocoyama
1
520
ハノーバーメッセ2025座談会.pdf
iotcomjpadmin
0
150
データプラットフォーム技術におけるメダリオンアーキテクチャという考え方/DataPlatformWithMedallionArchitecture
smdmts
5
590
~宇宙最速~2025年AWS Summit レポート
satodesu
1
1.6k
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1.4k
白金鉱業Meetup_Vol.19_PoCはデモで語れ!顧客の本音とインサイトを引き出すソリューション構築
brainpadpr
2
500
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Scaling GitHub
holman
459
140k
Producing Creativity
orderedlist
PRO
346
40k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
920
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Building Applications with DynamoDB
mza
95
6.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
BBQ
matthewcrist
89
9.7k
The Cost Of JavaScript in 2023
addyosmani
51
8.4k
Transcript
#!/usr/bin/php PHP on the command line Tuesday, February 19, 13
./phpcl --overview • Basic PHP Commands • PHP Scripts •
Arguments • Real World Example Tuesday, February 19, 13
Practical PHP On the command line Tuesday, February 19, 13
php -v → php -v PHP 5.3.15 with Suhosin-Patch (cli)
(built: Aug 24 2012 17:45:44) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies Tuesday, February 19, 13
php --ini → php --ini Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) Tuesday, February 19, 13
php lint Tuesday, February 19, 13
php -l → php -l stdin.php No syntax errors detected
in stdin.php Tuesday, February 19, 13
php -l → php -l stdin.php PHP Parse error: parse
error in stdin.php on line 5 Errors parsing stdin.php Tuesday, February 19, 13
php -l • Automate during rollup, commits • Prevent silly
mistakes, because, let’s face it, you aren’t doing TDD • Sometimes tools might modify output, even accidentally • Ensures code can run on the version of PHP installed Tuesday, February 19, 13
php -a PHP’s interactive shell Not quite a REPL, doesn’t
really matter (Read-Evaluate-Print Loop) Tuesday, February 19, 13
php -a → php -a Interactive shell php > $a
= range(1,3); php > var_dump($a); array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Tuesday, February 19, 13
php -a php > class Foo { public $bar =
'baz'; } php > $foo = new Foo(); php > echo $foo->bar; baz Tuesday, February 19, 13
php -a php > function p($v){ php { echo md5('this_is_really_secure_right?'.$v);
php { } php > p(134); bb33942de0b7f8f7fda76ef41ee55654 php > p('happy'); fbc327fa6e16a971130d72bd72e7e55f Tuesday, February 19, 13
php -a php > var_dump(array()===array()); bool(true) php > var_dump( ((array)
new stdClass()) === array() ); bool(true) php > class Foo{function __toString(){return '';}} php > $foo = new Foo(); php > var_dump( ((string) $foo) === '' ); bool(true) Tuesday, February 19, 13
php -a • Great for resolving quick question • Winning
arguments • Temporary scripts, functions Tuesday, February 19, 13
php -a • Has autocomplete php > new PDO PDO
pdo_drivers PDOException PDORow PDOStatement Tuesday, February 19, 13
PHP Scripts Tuesday, February 19, 13
Running Scripts • Command Line • $ php ./script.php •
Bash Bang • #!/usr/bin/php Tuesday, February 19, 13
Command Line • Useful for executing code that might also
run from a web server • Doesn’t assume existing installation directory Tuesday, February 19, 13
Bash Bang • $ ./script.php • $ ./script • $
script • #!/usr/bin/env php > #!/usr/bin/php Tuesday, February 19, 13
getopt <?php $options = getopt("f:hp:"); var_dump($options); → php ./getopt.php -f
hello -p asdf -h array(3) { ["f"]=> string(5) "hello" ["p"]=> string(4) "asdf" ["h"]=> bool(false) } Tuesday, February 19, 13
getopt • f: - Required value • v:: - Optional
value • a - No value • $opts = getopt(‘f:v::a’); Tuesday, February 19, 13
getopt • getopt( $shortOptions, $longOptions ) Tuesday, February 19, 13
getopt long options • $longOptions = array( • ‘required:’, •
‘optional::’, • ‘option’ • ); • $ script --required 123 --optional=”value is here” --option Tuesday, February 19, 13
getopt • $opts = getopt(‘v’,array(‘verbose’)); • $ script -v •
$ script --verbose Tuesday, February 19, 13
getopt • php.net/getopt • > 5.3 Works on windows, plus
support for ::, =, and longopts • < 5.3 misses those critical features Tuesday, February 19, 13
time to see code Tuesday, February 19, 13