Swoole installed via pecl.
// example from readme
$http = new \swoole_http_server("0.0.0.0", 9501);
$http->on('request', function ($request, $response) {
$response->header("Content-Type", "text/html; charset=utf-8");
$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->start();
and output is
PHP Fatal error: Class 'swoole_http_server' not found
it's seems you must edit php.ini and add "extension=swoole.so". then restart httpd or php-fpm.
No, I have swoole .ini file parsed and registered correctly. If I try example with server it works.
check your swoole installation with
php -i | grep swoole
if you are using inside class you have to add \ or use statement otherwise you can use call normally new swoole_http_server()
@Atriedes as I mentioned everything is okay I doible checked. But I cannot find out why that class not exists :/.
what is your swoole version?
swoole_http_server availabile in version 1.7+

I install swoole via homebrew but I don't think so that is a problem.
could you update to latest version pls?
its not installation problem swoole_http_server is new feature I forget which version already have that feature.
Ok, it seems that homebrew registry installed older version. I try it via PECL and I have 1.7.18 now. It works. Thanks.
Env: Ubuntu 16.0 + PHP7.0
First thanks for better level of websocket library.
I faced same issues, I had installed with PECL
tejas@lp-snippetbucket:/var/www/html$ sudo pecl install swoole
pecl/swoole is already installed and is the same as the released version 1.9.14
install failed
PHP Fatal error: Uncaught Error: Class 'swoole_websocket_server' not found in /var/www/swoole.php:5
Stack trace:
thrown in /var/www/swoole.php on line 5
note:
Also in phpinfo() -> don't found swool.
note:
php -i | grep swoole
Gives no result.
What should I do ? so I can use this powered c based library.
I had updated in php.ini with extension=swoole.so than restart fpm and all works.
For those, who have tried all of the above, but nothing helped, just make sure your php.ini for PHP CLI is configured. Because there's 2 php.ini files.
@shumichenko thanks i was enabling the extension in /etc/php/7.2/apache2/php.ini instead of /etc/php/7.2/cli/php.ini
if you're using MAMP, make sure you use MAMP php binary.
mymac$ /Applications/MAMP/bin/php/php7.3.1/bin/php test.php
default php binary will give you Class 'swoole_http_server' not found.