Skip to content

Commit

Permalink
Add warning in examples if xdebug or assertions are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Mar 25, 2018
1 parent 27c98c1 commit 2cd81a8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/delayed-response.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/support/bootstrap.php";

use Amp\ByteStream\ResourceOutputStream;
use Amp\Delayed;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\Server;
use Amp\Http\Server\Support\Recommender;
use Amp\Http\Status;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
Expand Down Expand Up @@ -38,6 +39,8 @@
], "Hello, World!");
}), $logger);

$server->attach(new Recommender);

yield $server->start();

// Stop the server when SIGINT is received (this is technically optional, but it is best to call Server::stop()).
Expand Down
5 changes: 4 additions & 1 deletion examples/exception.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/support/bootstrap.php";

use Amp\ByteStream\ResourceOutputStream;
use Amp\Http\Server\Support\Recommender;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
Expand All @@ -28,6 +29,8 @@
throw new \Exception("Something went wrong :-(");
}), $logger);

$server->attach(new Recommender);

yield $server->start();

// Stop the server when SIGINT is received (this is technically optional, but it is best to call Server::stop()).
Expand Down
5 changes: 4 additions & 1 deletion examples/hello-world.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/support/bootstrap.php";

use Amp\ByteStream\ResourceOutputStream;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\Server;
use Amp\Http\Server\Support\Recommender;
use Amp\Http\Status;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
Expand All @@ -33,6 +34,8 @@
], "Hello, World!");
}), $logger);

$server->attach(new Recommender);

yield $server->start();

// Stop the server when SIGINT is received (this is technically optional, but it is best to call Server::stop()).
Expand Down
5 changes: 4 additions & 1 deletion examples/state.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/support/bootstrap.php";

use Amp\ByteStream\ResourceOutputStream;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\Server;
use Amp\Http\Server\Support\Recommender;
use Amp\Http\Status;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
Expand Down Expand Up @@ -39,6 +40,8 @@
], "You're visitor #" . (++$counter) . ".");
}), $logger);

$server->attach(new Recommender);

yield $server->start();

// Stop the server when SIGINT is received (this is technically optional, but it is best to call Server::stop()).
Expand Down
5 changes: 4 additions & 1 deletion examples/stream.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/support/bootstrap.php";

use Amp\ByteStream\IteratorStream;
use Amp\ByteStream\ResourceOutputStream;
Expand All @@ -11,6 +11,7 @@
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\Server;
use Amp\Http\Server\Support\Recommender;
use Amp\Http\Status;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
Expand Down Expand Up @@ -43,6 +44,8 @@
})));
}), $logger, (new Options)->withoutCompression());

$server->attach(new Recommender);

yield $server->start();

// Stop the server when SIGINT is received (this is technically optional, but it is best to call Server::stop()).
Expand Down
33 changes: 33 additions & 0 deletions examples/support/Recommender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Amp\Http\Server\Support;

use Amp\Http\Server\Server;
use Amp\Http\Server\ServerObserver;
use Amp\Promise;
use Amp\Success;

final class Recommender implements ServerObserver {
/** @inheritdoc */
public function onStart(Server $server): Promise {
$logger = $server->getLogger();

if (\extension_loaded('xdebug')) {
$logger->warning('The "xdebug" extension is loaded, this has a major impact on performance.');
}
try {
if (!@\assert(false)) {
$logger->warning("Assertions are enabled, this has a major impact on performance.");
}
} catch (\AssertionError $exception) {
$logger->warning("Assertions are enabled, this has a major impact on performance.");
}

return new Success;
}

/** @inheritdoc */
public function onStop(Server $server): Promise {
return new Success;
}
}
5 changes: 5 additions & 0 deletions examples/support/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

/** @var Composer\Autoload\ClassLoader $loader */
$loader = require dirname(__DIR__, 2) . '/vendor/autoload.php';
$loader->addPsr4('Amp\Http\Server\Support\\', __DIR__);

0 comments on commit 2cd81a8

Please sign in to comment.