-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
69 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
### Environment Variables | ||
|
||
```php | ||
$name = getenv('DEMO_NAME'); | ||
$apiKey = getenv('API_KEY'); | ||
|
||
if ($name) { | ||
printf('Hey, I recognize you, %s!' . PHP_EOL, $name); | ||
$name = sprintf('My old friend, %s!', $name); | ||
// It wasn't provided via environment variable. | ||
if (! $apiKey && ! empty($argv[1])) { | ||
$apiKey = $argv[1]; | ||
} | ||
|
||
} else { | ||
echo "I don't know you, so I'll just call you Fred." . PHP_EOL; | ||
$name = 'Fred'; | ||
// Neither environment nor argument. | ||
if (! $apiKey) { | ||
echo 'An API key must be provided!'; | ||
exit(1); | ||
} | ||
|
||
// Update DEMO_NAME and call the system's echo program. | ||
putenv('DEMO_NAME=' . $name); | ||
passthru('echo $DEMO_NAME'); | ||
echo "API Key: $apiKey"; | ||
``` | ||
|
||
Note: | ||
|
||
Another neat trick is the ability to access environment variables from within your PHP script. | ||
Another neat trick is the ability to access environment variables from within your PHP script. | ||
|
||
Can use both getenv() and putenv(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
### Environment Variables | ||
|
||
`export DEMO_NAME="Steve"` | ||
```html | ||
> Hey, I recognize you, Steve! | ||
> My old friend, Steve! | ||
```sh | ||
$ API_KEY=abc123 php my-script.php | ||
|
||
API Key: abc123 | ||
``` | ||
<!-- .element: class="fragment" --> | ||
|
||
```sh | ||
$ php my-script.php xyz789 | ||
|
||
<br>Otherwise: | ||
```html | ||
> I don't know you, so I'll just call you Fred. | ||
> Fred | ||
API Key: xyz789 | ||
``` | ||
<!-- .element: class="fragment" --> | ||
|
||
```sh | ||
$ API_KEY=abc123 php my-script.php xyz789 | ||
|
||
API Key: abc123 | ||
``` | ||
<!-- .element: class="fragment" --> | ||
|
||
Note: | ||
|
||
Since the script was checking for the environment variable first, that will take precedence when the script is run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
## Thank You! | ||
|
||
Steve Grunwell<br> | ||
[stevegrunwell.com](https://stevegrunwell.com)<br> | ||
[liquidweb.com](https://www.liquidweb.com) | ||
Senior Software Engineer, Liquid Web | ||
|
||
[stevegrunwell.com/slides/php-cli](https://stevegrunwell.com/slides/php-cli)<!-- .element: class="slides-link" --> | ||
<p class="slides-link"> | ||
[stevegrunwell.com/slides/php-cli](https://stevegrunwell.com/slides/php-cli)<br>[joind.in/talk/b9a05](https://joind.in/talk/b9a05) | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters