php-binance-api
php-binance-api copied to clipboard
how to listen to websocket in background?
how to listen to websocket in background?
Hello,
This question has multiple solutions, you can find multiple path on the internet.
One solution that come to my mind would by to use the Symfony's Console component and run your scripts the the &
operator.
An example of what the solution could be:
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ListenSocketCommand extends Command
{
protected static $defaultName = 'app:listen-socket';
protected function execute(InputInterface $input, OutputInterface $output)
{
$api = new API('apiKey', 'apiSecret');
$api->kline(["BTCUSDT", "EOSBTC"], "5m", function($api, $symbol, $chart) {
// do whatever you want
});
return Command::SUCCESS;
}
}
And call the command by doing (in a terminal)
bin/console app:listen-socket &
(the last char is where the magic happens)