PHP Fatal error: Uncaught Error: Class 'Amp\Log\StreamHandler' not found in
Open
Nobody has claimed this yet.
question
- Dominant language
- PHP
- Stars
- 1.3k
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Description
I am unable to run the sample in the documentation because the logger is not working using the command and the code below.
Install as composer dependency
$composer require amphp/http-server --dev
Run Code
$php test.php
<?php
use Amp\ByteStream;
use Amp\Http\HttpStatus;
use Amp\Http\Server\DefaultErrorHandler;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\SocketHttpServer;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;
require __DIR__.'/vendor/autoload.php';
// Note any PSR-3 logger may be used, Monolog is only an example.
$logHandler = new StreamHandler(ByteStream\getStdout());
$logHandler->pushProcessor(new PsrLogMessageProcessor());
$logHandler->setFormatter(new ConsoleFormatter());
$logger = new Logger('server');
$logger->pushHandler($logHandler);
$requestHandler = new class() implements RequestHandler {
public function handleRequest(Request $request) : Response
{
return new Response(
status: HttpStatus::OK,
headers: ['Content-Type' => 'text/plain'],
body: 'Hello, world!',
);
}
};
$errorHandler = new DefaultErrorHandler();
$server = SocketHttpServer::createForDirectAccess($logger);
$server->expose('127.0.0.1:1337');
$server->start($requestHandler, $errorHandler);
// Serve requests until SIGINT or SIGTERM is received by the process.
Amp\trapSignal([SIGINT, SIGTERM]);
$server->stop();
Im getting the error
PHP Fatal error: Uncaught Error: Class 'Amp\Log\StreamHandler' not found in
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documentation sample, its Composer install command, and the Amp\Log\StreamHandler import shown in the report. Reproduce the failure with php test.php after installing the documented dependency, then verify that the sample runs without the reported fatal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100