Skip to content

Commit bb58b5b

Browse files
committed
Clean up the section on running other commands
1 parent 4060346 commit bb58b5b

File tree

5 files changed

+20
-101
lines changed

5 files changed

+20
-101
lines changed

slides.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -667,33 +667,21 @@ The most common ways you'll see PHP call other scripts
667667

668668
<dl>
669669
<dt><a href="https://www.php.net/manual/en/function.system.php"><code>system()</code></a></dt>
670-
<dd></dd>
670+
<dd>Returns last line of output, flushes buffer as it goes</dd>
671671
<dt><a href="https://www.php.net/manual/en/function.passthru.php"><code>passthru()</code></a></dt>
672-
<dd>Returns raw output</dd>
673672
<dd>Best choice for binary files</dd>
674673
</dl>
675674

676675
Note:
677676

678677
* `system()`
678+
* Works the same as its C equivalent
679+
* Will attempt to flush the output buffer as it goes, but only returns the last line (and can set exit code to a variable by reference)
679680
* `passthru()` doesn't attempt to transform the output, so this is really useful when working within binary files like images, video, etc.
680681
* Link in slides' README explaining how I used it to generate animated thumbnails for gifs
681682

682683
----
683684

684-
### Calling other scripts
685-
686-
<dl>
687-
<dt><a href="https://www.php.net/manual/en/function.proc-open.php"><code>proc_open()</code></a></dt>
688-
<dd></dd>
689-
<dt><a href="https://www.php.net/manual/en/function.pcntl-exec.php"><code>pcntl_exec()</code></a></dt>
690-
<dd></dd>
691-
</dl>
692-
693-
Note:
694-
695-
----
696-
697685
<!-- .slide: data-background-image="resources/spidey-sense.png" data-background-position="left bottom" data-background-size="contain" data-hide-footer -->
698686

699687
Note:
@@ -1076,6 +1064,23 @@ Note:
10761064

10771065
----
10781066

1067+
### Don't let scripts be run from a browser!
1068+
1069+
If your commands live within the web root, prevent them from being run outside the CLI:
1070+
1071+
```php
1072+
// Prevent this script from being run outside of a CLI context
1073+
if (PHP_SAPI !== 'cli') {
1074+
exit;
1075+
}
1076+
```
1077+
1078+
Note:
1079+
1080+
Modern frameworks keep most app code out of the web root, but if you're writing commands that will live under the web root **be sure that they can't be executed by a web request!**
1081+
1082+
----
1083+
10791084
### Swanson on Commands
10801085

10811086
![Ron Swanson (Nick Offerman) advising "Never half-ass two things. Whole-ass one thing."](resources/whole-ass.gif)

slides/wp-cli-example.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

slides/wp-cli-example2.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

slides/wp-cli-example3.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

slides/wp-cli-example4.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)