Skip to content

Commit 5f849a3

Browse files
chingor13bshaffer
authored andcommitted
Add Debugger samples (GoogleCloudPlatform#507)
1 parent 894829b commit 5f849a3

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

debugger/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Google Stackdriver Debugger PHP Sample Application
2+
3+
## Description
4+
5+
This simple [Silex][silex] application demonstrates how to
6+
install and run the Stackdriver Debugger Agent for PHP.
7+
8+
## Build and Run
9+
10+
1. Add the Stackdriver Debugger composer package to your `composer.json`:
11+
```
12+
$ composer require google/cloud-debugger:^0.1
13+
```
14+
2. Install the composer package:
15+
```
16+
$ composer install
17+
```
18+
3. Install the PHP extension from [PECL][pecl]:
19+
```
20+
$ pecl install stackdriver_debugger-alpha
21+
```
22+
4. Run the Stackdriver Debugger daemon:
23+
```
24+
$ vendor/bin/google-cloud-debugger .
25+
```
26+
5. Run the AsyncBatchDaemon daemon:
27+
```
28+
$ vendor/bin/google-cloud-batch daemon
29+
```
30+
6. Run the application:
31+
```
32+
$ IS_BATCH_DAEMON_RUNNING=true php -S localhost:8000 -t web/
33+
```
34+
7. Navigate to the [Google Cloud Debugger console][debug-console] and [Select Source Code][select-source-code]
35+
8. [Set a snapshot][snapshots] or [set a logpoint][logpoints].
36+
37+
See [Setting Up Stackdriver Debugger for PHP](https://cloud.google.com/debugger/docs/setup/php)
38+
for more information.
39+
40+
## Contributing changes
41+
42+
* See [CONTRIBUTING.md][contributing]
43+
44+
## Licensing
45+
46+
* See [LICENSE][license]
47+
48+
[silex]: https://silex.symfony.com/
49+
[pecl]: https://pecl.php.net/
50+
[debug-console]: https://console.cloud.google.com/debug
51+
[select-source-code]: https://cloud.google.com/debugger/docs/source-options]
52+
[snapshots]: https://cloud.google.com/debugger/docs/using/snapshots
53+
[logpoints]: https://cloud.google.com/debugger/docs/using/logpoints
54+
[contributing]: ../../CONTRIBUTING.md
55+
[license]: ../../LICENSE

debugger/composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "google/debugger-sample",
3+
"type": "project",
4+
"require": {
5+
"php": ">= 7.0",
6+
"google/cloud-debugger": "^0.1.0",
7+
"silex/silex": "~2.0",
8+
"twig/twig": "^2.3"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "~4"
12+
}
13+
}

debugger/views/hello.html.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<html>
3+
<head>
4+
<title>Hello from Silex {{ constant('Silex\\Application::VERSION') }}title>
5+
head>
6+
<body>
7+
<h1>Hello {{ name }} from Silex {{ constant('Silex\\Application::VERSION') }}h1>
8+
body>
9+
html>

debugger/web/index.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/**
3+
* Copyright 2017 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
# [START debugger_agent]
18+
require_once __DIR__ . '/../vendor/autoload.php';
19+
20+
use Google\Cloud\Debugger\Agent;
21+
22+
$agent = new Agent(['sourceRoot' => realpath('../')]);
23+
# [END debugger_agent]
24+
$app = new Silex\Application();
25+
26+
$app->register(new Silex\Provider\TwigServiceProvider(), array(
27+
'twig.path' => __DIR__ . '/../views',
28+
));
29+
30+
$app->get('/', function () {
31+
return 'Silex version ' . Silex\Application::VERSION;
32+
});
33+
34+
$app->get('/hello/{name}', function ($name) use ($app) {
35+
return $app['twig']->render('hello.html.twig', [
36+
'name' => $name
37+
]);
38+
});
39+
40+
$app->run();

0 commit comments

Comments
 (0)