swoole / yasd

Yet Another Swoole Debugger
https://huanghantao.github.io/yasd-wiki/
Apache License 2.0
357 stars 35 forks source link

"php -e" causes segmentation fault #154

Closed marko-ilic closed 1 year ago

marko-ilic commented 3 years ago

When php script with the code for creating swoole server is run with php, everything works fine (except yasd), but if the script is run with option -e (php -e) segmentation fault will be returned.

Swoole version: 4.8.0

OS: 5.10.47-linuxkit x86_64 Linux gcc version 10.3.1 20210424 (Alpine 10.3.1_git20210424) PHP 8.0.11

How to reproduce: index.php file

<?php 

// ...

$server = new  Swoole\Http\Server("127.0.0.1", 9501);

$server->on("start", function (Server $server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

run the script with php -e index.php

output: Segmentation fault

yasd is installed with

git clone https://github.com/swoole/yasd.git \
    && cd yasd \
    && /usr/local/bin/phpize --clean \
    && /usr/local/bin/phpize \
    && ./configure \
    && make clean \
    && make \
    && make install

php -m

...
Yasd
...
deminy commented 3 years ago

it seems that some use statements are missing. Could you please add them and try again?

<?php

use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

// ...

BTW, I tested Swoole 4.8.0 with PHP 7.4 and 8.0 (using the script provided and following instructions here), and it worked fine.

marko-ilic commented 3 years ago

@deminy I didn't copy that part, but it's the same. Here is the whole script index.php

<?php

// update with the path to your vendor
require __DIR__ . '/../vendor/autoload.php';

use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$server = new Server("127.0.0.1", 9501);

$server->on("start", function (Server $server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

And just to mention it worked fine few weeks ago with swoole 4.7.0

deminy commented 3 years ago

I tested the code without the autoloading part, and it worked fine. Could you please remove the autoloading part, try again, and see if it still happens?

It it doesn't happen, there could some coding issue or compatibility issue with some Composer packages. It would be nice if you could include a reproducible code (with Composer and other details included).

marko-ilic commented 3 years ago

It's the same. I've created this simple example just to show what is the problem, and it's the same with or without autoload part. I have (apart from the project where the issue is the same) empty project with just index.php file and composer

...
    "require": {
        "php": "^8.0",
        "ext-swoole": "^4.8.0"
    },
...

And this issue is not only on one machine

Without -e swoole works fine (Swoole http server is started at http://127.0.0.1:9501)

UPDATE: I've tested it now with the swoole 4.7.0 and the error is the same (Segmentation fault). It was ok few weeks ago, so I'm not sure what can be the reason :-(

deminy commented 3 years ago

Tested on my Macbook as well with following installations. This time I didn't use Docker, but still don't see the issue.

demin$ php -v
PHP 8.0.11 (cli) (built: Sep 26 2021 20:58:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.11, Copyright (c), by Zend Technologies

demin$ php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.8.0
Built => Oct 18 2021 13:50:08
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1l  24 Aug 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 262144 => 262144

demin$ php --ri yasd

yasd

Yasd => enabled
Author => codinghuang <codinghuang@qq.com>
Version => 0.3.9-alpha
Built => Oct 18 2021 13:57:39

Directive => Local Value => Master Value
yasd.breakpoints_file => no value => no value
yasd.debug_mode => remote => remote
yasd.remote_host => 127.0.0.1 => 127.0.0.1
yasd.remote_port => 9000 => 9000
yasd.depth => 1 => 1
yasd.log_level => -1 => -1
yasd.max_executed_opline_num => 0 => 0
yasd.init_file => no value => no value
yasd.open_extended_info => 0 => 0
xdebug.coverage_enable => 1 => 1
xdebug.profiler_enable => 1 => 1
xdebug.remote_autostart => 1 => 1
xdebug.remote_connect_back => 0 => 0
xdebug.remote_mode => req => req
xdebug.idekey => hantaohuang => hantaohuang
Rastusik commented 3 years ago

I have the same Segmentation fault problem with these settings:

php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.5.11
Built => Oct 24 2021 20:41:37
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

php --ri yasd

yasd

Yasd => enabled
Author => codinghuang <codinghuang@qq.com>
Version => 0.3.9-alpha
Built => Oct 24 2021 20:41:37

Directive => Local Value => Master Value
yasd.breakpoints_file => no value => no value
yasd.debug_mode => remote => remote
yasd.remote_host => 127.0.0.1 => 127.0.0.1
yasd.remote_port => 9000 => 9000
yasd.depth => 1 => 1
yasd.log_level => -1 => -1
yasd.max_executed_opline_num => 0 => 0
yasd.init_file => no value => no value
yasd.open_extended_info => 0 => 0
xdebug.coverage_enable => 1 => 1
xdebug.profiler_enable => 1 => 1
xdebug.remote_autostart => 1 => 1
xdebug.remote_connect_back => 0 => 0
xdebug.remote_mode => req => req

A few weeks ago it worked.

Rastusik commented 3 years ago

UPDATE: it seems like it works again after I removed the blackfire extension

marko-ilic commented 3 years ago

It's the same in my case. It works after removing blackfire extension. Thanks @Rastusik

feelec-yishu commented 2 years ago

I don't want to install blackfilre. As long as I start yasd and run php -e, a segmentation fault (core dumped) will appear

huanghantao commented 1 year ago

Can consider to use swoole https://github.com/swoole/swoole-src/tree/support-xdebug

You can use xdebug directly, as long as the PHP version is 8.1 or greater