Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Command Line PHP Basics
Search
Jason Lotito
January 21, 2013
Technology
68
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Command Line PHP Basics
Jason Lotito
January 21, 2013
More Decks by Jason Lotito
See All by Jason Lotito
tmux
jasonlotito
1
52
Getting Things Done from Someone with OCD & ADHD
jasonlotito
0
99
How We Killed Our Process, Technology Stack, and Assumptions — and Survived
jasonlotito
0
61
Twitter Bootstrap, or why being a PHP Developer is a bad idea.
jasonlotito
2
570
require.js
jasonlotito
3
100
tmux
jasonlotito
0
150
Other Decks in Technology
See All in Technology
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
4
1.3k
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
2
910
20260912_スクフェス三河
kgnkhkr
0
380
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
おい、エージェントを使って終わらせろ
nwiizo
0
410
AI de Idea
kawaguti
PRO
2
120
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
24
16k
ユーザー価値を届け続けるためにウォンテッドリーが大切にしている文化
kotaminato
0
160
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
110
白金鉱業Meetup Vol.25 アウトカムが二値のデータに対するCausal Impact
brainpadpr
0
210
range over func 2年間の軌跡 Issue #56413 はGoのエコシステムをどう変えたか
ryujicre8ive
0
190
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
2
1.3k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
690
Become a Pro
speakerdeck
PRO
31
6.3k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Heart Work Chapter 1 - Part 1
lfama
PRO
10
36k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
460
The SEO Collaboration Effect
kristinabergwall1
1
560
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
720
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
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