Open Bezlepkin opened 5 years ago
Same here, how to do this?
You import it from the main file e.g in index2.php
'index.php' ```
Then you can use it in as usual
$io=require 'index.php'
$io=require 'index.php'
Don't work
What's the error you are getting?
On Fri, 21 Feb 2020 21:29 Davy Massoneto, notifications@github.com wrote:
$io=require 'index.php'
Don't work
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/walkor/phpsocket.io/issues/209?email_source=notifications&email_token=AE35ASMG7FQ7IL6GCPIHGJ3REATRLA5CNFSM4JFWPF4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMT2HDA#issuecomment-589800332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE35ASPRQYNOVGYC7JG6B3DREATRLANCNFSM4JFWPF4A .
"Need to create an instance of SocketIO twice?"
No, The first script/file should connect to the socket then you can use the Emitter to send from other PHP files or scripts.
For example i have two php files. index.php, index2.php. And both should send to the socket.
` use Workerman\Worker; use PHPSocketIO\SocketIO;
// listen port 2021 for socket.io client $io = new SocketIO(2021); $io->on('connection', function($socket)use($io){ $socket->on('chat message', function($msg)use($io){ $io->emit('chat message', $msg); }); });
Worker::runAll(); ` Need to create an instance of SocketIO twice?