opened
atyachin
username_0
Hi,

I'm new to Workerman.
I'm trying to implement a simple WebSocket client that listens on a remote socket, print out the messages and exists after X minutes (where X is an argument).
I followed the AsyncTcpConnection sample in the project's homepage, however it's not clear to me where's the best place to call Worker::stopall(). 
Placing it inside $ws_connection->onMessage would not guarantee a proper exit after X minutes, and I don't want to depend on a message to arrive in order to exit the client.

Any advice would be appreciated.

Thanks.
Simple WebSocket client - exit after X minutes
issue
created
atyachin
username_0
I tried the following:

$worker->onWorkerStart` = function() use ($maxtime) {
                // set timer to exit the process
                \Workerman\Lib\Timer::add($maxtime, function() {
                    echo "Work ended.".PHP_EOL;
                    Worker::stopAll();
                });            
              // do more stuff


However, the process is terminated and immediately restarting...
comment
created
walkor
username_1
try the following:
```php
$worker->onWorkerStart = function() use ($maxtime) {
    // set timer to exit the process
    \Workerman\Lib\Timer::add($maxtime, function() {
        echo "Work ended.".PHP_EOL;
        // Send signal SIGINT to master pid and then stop all processes.
        posix_kill(posix_getppid(), SIGINT);
    });
    // do more stuff
```
comment
closed
walkor
username_1
issue