Coder Social home page Coder Social logo

phpsocket.io's People

Contributors

adrianofoschi avatar alexras007 avatar benwaffle avatar binemmanuel avatar buri avatar d4wae89d498 avatar detain avatar devbrom avatar ecmchow avatar erlangparasu avatar fly2xiang avatar imk812 avatar jichangfeng avatar luckycyborg avatar neumann-valle avatar oittaa avatar saidmoya12 avatar samnela avatar sparkinzy avatar stalinone avatar tautrimas avatar walkor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpsocket.io's Issues

Not Working.

Cannot get this to talk together. Using SSL. Using simple chat method and simple chat from socket io.

Trying to get socket.IO-objc to work with socket.io's chat example

I am using socket.io's chat example php based (https://github.com/walkor/phpsocket.io) , and I can receive messages. However, I can't send messages. While attempting to set the nickname, I get a crash on the node instance.
On the iOS side, I send a message in the socketDidConnect method after my viewDidLoad method...

(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.socketIO = [[SocketIO alloc] initWithDelegate:self];
self.socketIO.useSecure = NO;

[self.socketIO connectToHost:@"localhost" onPort:3000];
}
```

(void) socketIODidConnect:(SocketIO *)socket{
NSLog(@"We connected....");
[self.socketIO sendEvent:@"add user" withData:@"testUser"];
}``

On the server side function add user:
  // when the client emits 'add user', this listens and executes
    $socket->on('add user', function ($username) use($socket){
        global $usernames, $numUsers;
        // we store the username in the socket session for this client
        $socket->username = $username;
        // add the client's username to the global list
        $usernames[$username] = $username;
        ++$numUsers;
        $socket->addedUser = true;
        $socket->emit('login', array( 
            'numUsers' => $numUsers
        ));
        // echo globally (all clients) that a person has connected
        $socket->broadcast->emit('user joined', array(
            'username' => $socket->username,
            'numUsers' => $numUsers
        ));
    });

How i can set username and send messages?

Access PHP session.

Hi, i am watching this repo and would like to use it. But I have a question, can we access php session?

If so any snippe how to accomplish it?

Fatal error: Call on removeAllListeners() on a non-object

I have the following error:



Fatal error: Call to a member function removeAllListeners() on a non-object in /opt/serverSideNode/php_socket.io/vendor/workerman/phpsocket.io/src/Client.php on line 252
WORKER EXIT UNEXPECTED E_ERROR Call to a member function removeAllListeners() on a non-object in /opt/serverSideNode/php_socket.io/vendor/workerman/phpsocket.io/src/Client.php on line 252
worker[PHPSocketIO:2024] exit with status 65280

What is the correct usage of $socket->disconnect(); does the argument needs to be given and what is the correct argument?

Please a correct usage must be given, using true as argument give me the above error..

trouble with install

I installed by php composer.phar install with composer.json found on github.
when I start server.php, I obtain the following message :
"Class 'Workerman\PHPSocketIO\SocketIO' not found in ....server.php at line xx"
Any idea ??

How to Broadcast notification to every user?

How can I use your repo to broadcast any notification to all users without user interaction i.e. currently there must be some client side activity (as of my knowledge) to notify other users, but i want to notify users from server, actually it will be a count down timer based on server time.

Multiple servers for Development/Production setup

Hi, I have a webapp that uses this socketio implementation for a chat/notification box.

Recently, I needed to split my app into DEV and PROD versions so I added a check on my server.php to detect the folder name and change ports accordingly.

Something like this:

// detect environment
$mode = (strpos(dirname(__DIR__), '-dev') !== false) ? 'dev' : 'prod';

if($mode === 'dev') {
    $channel = new Channel\Server('0.0.0.0', 3206);
    $io = new SocketIO(3020);
} elseif($mode === 'prod') {
    $channel = new Channel\Server('0.0.0.0', 2206);
    $io = new SocketIO(2020);
}

So, if I run "server.php start" inside a folder that has "-dev" in the name, it starts the servers on ports 3020/3206, otherwise it will start on ports 2020/2206.

This is working fine, but the servers seem to be communicating with each other, because when I type something on the DEV's chat message, the message appears on the PROD and vice-versa.

I've used Chrome developer tools to check the connections and each version seems to be correctly connected to the different versions, so:

PROD app at "myapp.example.com" is connected to wss://myapp.example.com/socket.io/...
DEV app at "myapp-dev.example.com" is connected to wss://myapp-dev.example.com/socket.io/...

In case it helps here are the status message for both when there's one user connected to each version:

DEV:

Workerman[server.php] status
---------------------------------------GLOBAL STATUS--------------------------------------------
Workerman version:3.3.4          PHP version:5.6.27-0+deb8u1
start time:2016-12-02 20:10:37   run 0 days 0 hours
load average: 0.05, 0.05, 0.05   event-loop:select
2 workers       2 processes
worker_name   exit_status     exit_count
ChannelServer 0                0
PHPSocketIO   0                0
---------------------------------------PROCESS STATUS-------------------------------------------
pid	memory  listening               worker_name   connections total_request send_fail throw_exception
3301	1.75M   frame://0.0.0.0:3206    ChannelServer 0           0              0         0
3302	2.75M   socketIO://0.0.0.0:3020 PHPSocketIO   3           255            0         0

PROD:

Workerman[server.php] status
---------------------------------------GLOBAL STATUS--------------------------------------------
Workerman version:3.3.4          PHP version:5.6.27-0+deb8u1
start time:2016-12-02 20:10:32   run 0 days 0 hours
load average: 0.12, 0.07, 0.05   event-loop:select
2 workers       2 processes
worker_name   exit_status     exit_count
ChannelServer 0                0
PHPSocketIO   0                0
---------------------------------------PROCESS STATUS-------------------------------------------
pid	memory  listening               worker_name   connections total_request send_fail throw_exception
3295	1.75M   frame://0.0.0.0:2206    ChannelServer 2           273            0         0
3296	2.75M   socketIO://0.0.0.0:2020 PHPSocketIO   3           292            0         0

So, my question is, how can I run two completely separate versions so I can properly separate my development tests from the production version?

Thank you.

how use of function

$io = new SocketIO(8000);
$io->of('/activity')->on('connection', function($socket){
    var_dump($socket);

    $activity->emit('hello', ['msg' => 'hello world']);
});

client can't receive msg, and no var_dump msg

peer to peer connecion

Is it possible to send messages only peer to peer instead of broadcasting ?
I want to reply only to the message sender

$socket->broadcast->emit('user joined', array(
            'username' => $username,
            'numUsers' => $numUsers,
        ));

php -d 之后,socket.io.js 出现400

php index.php start -d; 出现 400 (Bad Request),同域名下也不能访问了
php index.php start &; 没有问题,也可以垮域
PHP环境是5.4.3

Share sessions between php app and socketio app

I'm using Yii2 and I'm trying to figure out how I could use this library with an existing app. Could you point to an example of a shared session/cookie system? A simple example would be to login via the main app and leverage the same cookie and session to skip authorization of a websocket session.

Great work btw. Thanks!

Sending events from php

Hi there, I'm using a slightly modified version of this project's chat demo.

Now, i have a question: Can I send messages to the chat from a php script or separate php app?

For example: I wanted to send a chat to everybody when something get's stored on the database. (e.g.: "user X has added/modified product Y" type messages)

Thanks

Hi, walkor. Need PHPSocketIO secure(https)

I am developing webrtc signaling server with phpsocketio for video chat application. So i need php socket io server as secure(https).. how to make php socket io server ssl .. This library is awesome. i can't leave this because of this silly reason. please help me out. Thanks. mail Id : [email protected]
can you please help me out ?

Cross Origin not working

I have set the origin like

$io = new SocketIO(2020);
$io->origins('http://example.com:8080');


Its not blocking other domain from connecting it

Error during WebSocket handshake: Unexpected response code: 400

This error appears when trying to reconnect after I used pcntl_fork() inside a socket listener callback.

$app = new SocketIO(8303);
$app->on('connection', function($socket) {
    $socket->('action', function() use ($socket) {
        if (pcntl_fork())
        {
            sleep(2); // do something that takes some secs
            $socket->emit('action success');
        }
    });
});

Any other workaround or fix instead of using an AsyncTcpConnectio mentioned here? #27 (comment)

Proper way to use Namespaces?

What is the proper way to use namespaces? I've been trying different things for the past hour and I still just get the "no socket for namespace _____" error.

Thanks for your time,

Joe

无初始值报错

发现
phpsocket.io/src/Event/Emitter.php 81行的

php public function emit($event_name)

$event_name 没有初始值为空的话,会报错。
#0 /home/wwwroot/vendor/workerman/phpsocket.io/src/Event/Emitter.php(81): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Missing argumen...', '/home/wwwroot/p...', 81, Array)
#1 [internal function]: PHPSocketIO\Event\Emitter->emit()
#2 /home/wwwroot/vendor/workerman/phpsocket.io/src/Socket.php(306): call_user_func_array(Array, Array)
#3 /home/wwwroot/vendor/workerman/phpsocket.io/src/Socket.php(268): PHPSocketIO\Socket->onevent(Array)
#4 /home/wwwroot/vendor/workerman/phpsocket.io/src/Client.php(201): PHPSocketIO\Socket->onpacket(Array)
#5 [internal function]: PHPSocketIO\Client->ondecoded(Array)
#6 /home/wwwroot/vendor/workerman/phpsocket.io/src/Event/Emitter.php(91): call_user_func_array(Array, Array)
#7 /home/wwwroot/vendor/workerman/phpsocket.io/src/Parser/Decoder.php(34): PHPSocketIO\Event\Emitter->emit('decoded', Array)
#8 /home/wwwroot/vendor/workerman/phpsocket.io/src/Client.php(181): PHPSocketIO\Parser\Decoder->add('2["room\/create...')
#9 [internal function]: PHPSocketIO\Client->ondata('2["room\/create...')
#10 /home/wwwroot/vendor/workerman/phpsocket.io/src/Event/Emitter.php(91): call_user_func_array(Array, Array)
#11 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Socket.php(183): PHPSocketIO\Event\Emitter->emit('data', '2["room\/create...')
#12 [internal function]: PHPSocketIO\Engine\Socket->onPacket(Array)
#13 /home/wwwroot/vendor/workerman/phpsocket.io/src/Event/Emitter.php(91): call_user_func_array(Array, Array)
#14 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Transport.php(56): PHPSocketIO\Event\Emitter->emit('packet', Array)
#15 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Transports/Polling.php(151): PHPSocketIO\Engine\Transport->onPacket(Array)
#16 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Transports/Polling.php(120): PHPSocketIO\Engine\Transports\Polling->onData('254:42["room\/c...')
#17 [internal function]: PHPSocketIO\Engine\Transports\Polling->dataRequestOnEnd(Object(PHPSocketIO\Engine\Protocols\Http\Request))
#18 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Protocols/SocketIO.php(177): call_user_func(Array, Object(PHPSocketIO\Engine\Protocols\Http\Request))
#19 /home/wwwroot/vendor/workerman/phpsocket.io/src/Engine/Protocols/SocketIO.php(89): PHPSocketIO\Engine\Protocols\SocketIO::emitEnd(Object(Workerman\Connection\TcpConnection), Object(PHPSocketIO\Engine\Protocols\Http\Request))
#20 [internal function]: PHPSocketIO\Engine\Protocols\SocketIO::onData(Object(Workerman\Connection\TcpConnection), '254:42["room\/c...')
#21 /home/wwwroot/vendor/workerman/workerman/Connection/TcpConnection.php(419): call_user_func('\PHPSocketIO\En...', Object(Workerman\Connection\TcpConnection), '254:42["room\/c...')
#22 [internal function]: Workerman\Connection\TcpConnection->baseRead(Resource id #859)
#23 /home/wwwroot/vendor/workerman/workerman/Events/Select.php(250): call_user_func_array(Array, Array)
#24 /home/wwwroot/vendor/workerman/workerman/Worker.php(1464): Workerman\Events\Select->loop()
#25 /home/wwwroot/vendor/workerman/workerman/Worker.php(898): Workerman\Worker->run()
#26 /home/wwwroot/vendor/workerman/workerman/Worker.php(864): Workerman\Worker::forkOneWorker(Object(Workerman\Worker))
#27 /home/wwwroot/vendor/workerman/workerman/Worker.php(422): Workerman\Worker::forkWorkers()
#28 /home/wwwroot/app/Console/Commands/Lives.php(1267): Workerman\Worker::runAll()
#29 [internal function]: App\Console\Commands\Lives->handle()
#30 /home/wwwroot/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#31 /home/wwwroot/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#32 /home/wwwroot/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /home/wwwroot/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /home/wwwroot/vendor/symfony/console/Application.php(791): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /home/wwwroot/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\Lives), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /home/wwwroot/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /home/wwwroot/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /home/wwwroot/artisan(46): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 {main}

Origins , where is your api docs?

Hi, @walkor hope you are fine..

Can you post the link where you phpsocket.io api is located, I am trying to restrict ORIGIN to my domain, can you tell me how is this accomplished?

regards

Connection closes when starting a new thread using pthreads

I'm building a chat application using your library and for longer database/api calls I decided to use multi-threading to prevent blocking all other interactions when fetching new data or similar.

For this I am using pthreads with a wrapper class to call a method threaded.

class ThreadedCall extends \Worker
{

    protected static $nextThreadId = 1;

    protected $method = null;

    protected $params = [];

    private function __construct($threadId, $method, array $params = [])
    {
        $this->threadId = $threadId;
        $this->method   = $method;
        $this->params   = $params;
    }

    public static function call($method, array $params = [])
    {
        $threadId = static::$nextThreadId++;
        $thread   = new self($threadId, $method, $params);

        if ($thread->start())
        {
            return $thread;
        }

        return null;
    }

    public function run()
    {
        if ($this->method !== null)
        {
            call_user_func_array($this->method, $this->params);
        }
    }

}
$socket->on('login', function() {
    ThreadedCall::call(function() {
        // do something that takes a long time
    });
});

So when I execute something threaded the socket gets closed immediately with the following error information, passed to the first argument in the disconnect callback client error.

What I am doing wrong or is the way I am following to reach a non-blocking client application with long-time-calls wrong?

call to member packet() on non object

Hi,

`
PHP Notice: Trying to get property of non-object in /php_socket.io/vendor/workerman/phpsocket.io/src/Socket.php on line 189

Notice: Trying to get property of non-object in /php_socket.io/vendor/workerman/phpsocket.io/src/Socket.php on line 189
PHP Fatal error: Call to a member function packet() on a non-object in /php_socket.io/vendor/workerman/phpsocket.io/src/Socket.php on line 192

Fatal error: Call to a member function packet() on a non-object in /php_socket.io/vendor/workerman/phpsocket.io/src/Socket.php on line 192
WORKER EXIT UNEXPECTED E_ERROR Call to a member function packet() on a non-object in /php_socket.io/vendor/workerman/phpsocket.io/src/Socket.php on line 192
`

I got this error : how to duplicate

server side..

<?php
// when the client emits 'new message', this listens and executes
    $socket->on('new message', function ($data)use($socket){
        // we tell the client to execute 'new message'
        $socket->broadcast->emit('new message', array(
            'username'=> $socket->username,
            'message'=> $data
        ));
    });
?>

and client side :

setInterval(function(){
    socket.emit('new message', { msg :'sending this from chrome.'});
  },1000);

Now just reload the browser f5 as many times, my guess is that when the browser is sending the payload the socket is disconnected and crashes the server...

thanks.

error on start socket

hi.
i when start the app , i got this error in command line:
error

please help me... :(

extra informations

Is it possible to receive extra information from the client ?
For example :

$socket->on('add user', function ($username) use($socket){
        global $usernames, $numUsers;
        // we store the username in the socket session for this client
        $socket->username = $username;
        // add the client's username to the global list
        $usernames[$username] = $username;
        ++$numUsers;
        $socket->addedUser = true;
        $socket->emit('login', array( 
            'numUsers' => $numUsers
        ));
        // echo globally (all clients) that a person has connected
        $socket->broadcast->emit('user joined', array(
            'username' => $socket->username . ' and extra information is : ' . $socket->extra,
            'numUsers' => $numUsers
        ));
    });

How to send and recive $socket->extra ?

xhr poll error

I wrote a very simple application to test communication between nodeJS and PHP.
Here's my code PHP (server side) :

`include DIR . '/../vendor/autoload.php';
use Workerman\Worker;
use Workerman\WebServer;
use Workerman\Autoloader;
use PHPSocketIO\SocketIO as Socket;

$io = new Socket(8000);

$io->on('connection', function($socket) {
echo ('new connection');
$socket->addedUser=false;
$socket->on('EVT1', function ($data) use ($socket){
vardump($data);
$socket->emit('ACK1', array('message'=>'EVT1 flushed'));
});
$socket->on('EVT2',function ($data) use ($socket){
$socket->emit('ACK2', array('message'=>'EVT2 flushed'));
});
});

$web = new WebServer('http://0.0.0.0:8002');
$web->addRoot('localhost', DIR . '/public');
Worker::runAll();`

Here's the code on the client side (nodeJS) :

var io = require('socket.io-client'); socket = io.connect('localhost', { port: 8000, reconnection : true }); socket.on('connect', function () { console.log("socket connected"); }); socket.on('connect_error', function(err) {console.log('connection error :'+err.message)}); socket.emit('EVT1', { user: 'me', msg: 'whazzzup?' }); socket.on('ACK1',function(data){console.log('received info : '+data);});

I obtain the following result : connection error : xhr poll error

Any idea ??

ErrorException: Declaration of PHPSocketIO\Socket::emit($ev) should be compatible with PHPSocketIO\Event\Emitter::emit($event_name = NULL)

ErrorException: Declaration of PHPSocketIO\Socket::emit($ev) should be compatible with PHPSocketIO\Event\Emitter::emit($event_name = NULL) in /Users/admin/Server/www/bandari/php-project/vendor/workerman/phpsocket.io/src/Socket.php:460
Stack trace:
#0 /Users/admin/Server/www/bandari/php-project/vendor/composer/ClassLoader.php(414): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Declaration of ...', '/Users/admin/Se...', 460, Array)
#1 /Users/admin/Server/www/bandari/php-project/vendor/composer/ClassLoader.php(414): include()
#2 /Users/admin/Server/www/bandari/php-project/vendor/composer/ClassLoader.php(301): Composer\Autoload\includeFile('/Users/admin/Se...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('PHPSocketIO\Soc...')
#4 /Users/admin/Server/www/bandari/php-project/vendor/workerman/phpsocket.io/src/Nsp.php(60): spl_autoload_call('PHPSocketIO\Soc...')
#5 /Users/admin/Server/www/bandari/php-project/vendor/workerman/phpsocket.io/src/Client.php(64): PHPSocketIO\Nsp->add(Object(PHPSocketIO\Client), Object(PHPSocketIO\Nsp), Array)
#6 /Users/admin/Server/www/bandari/php-project/vendor/workerman/phpsocket.io/src/SocketIO.php(100): PHPSocketIO\Client->connect('/')
#7 [internal function]: PHPSocketIO\SocketIO->onConnection(Object(PHPSocketIO\Engine\Socket))
#8 /Users/admin/Server/www/bandari/php-project/vendor/workerman/phpsocket.io/src/Event/Emitter.php(92): call_user_func_array(Array, Array)

新版本1.0.9有问题,换1.0.8就没有问题

Emit on a set interval

Hello,

Awesome framework, it is doing an amazing job powering one of my websites chatrooms. I did have a question however as I have not been able to solve this problem yet.

Basically, I would like to send a message to my chatroom every x minutes. I have figured out how this can be completed yet. I tried your example provided for workman, but have not been able to use both together.

Any feedback is appreciated,
Ray

How to use "Sending and getting data (acknowledgements)"

Example Node.JS from socket.io

Server

var io = require('socket.io')(80);

io.on('connection', function (socket) {
  socket.on('ferret', function (name, fn) {
    fn('woot');
  });
});

Client

<script>
  var socket = io(); // TIP: io() with no args does auto-discovery
  socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
    socket.emit('ferret', 'tobi', function (data) {
      console.log(data); // data will be 'woot'
    });
  });
</script>

How to use like this????

File

How i can send and receive files?

How to add header to implement CORS

My server-side and client-side socketio app are in different domains, so I suffer cross domain access problem. How to add CORS header at the server side like below? Thanks

Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept

发送时间格式错误问题

/Engine/Transports/PollingXHR.php 38行
$content_type = preg_match('/\d+:/', $data) ? 'text/plain; charset=UTF-8' : 'application/octet-stream';

这句会影响我发如下格式数据的类型错误使其socket.io客户端报:Error: server error错误。
$connection->emit('client_event', ['addtine' => '2016-11-19 16:21:00']);

因为socket.io源码里用了以下方式解析数据,所以没对应上:

Request.prototype.onLoad = function() {
var data;
try {
	var contentType;
	try {
		contentType = this.xhr.getResponseHeader("Content-Type").split(";")[0]
	} catch (e) {}
	if (contentType === "application/octet-stream") {
		data = this.xhr.response
	} else {
		if (!this.supportsBinary) {
			data = this.xhr.responseText
		} else {
			try {
				data = String.fromCharCode.apply(null, new Uint8Array(this.xhr.response))
				//console.log(data);
			} catch (e) {
				var ui8Arr = new Uint8Array(this.xhr.response);
				var dataArray = [];
				for (var idx = 0, length = ui8Arr.length; idx < length; idx++) {
					dataArray.push(ui8Arr[idx])
				}
				data = String.fromCharCode.apply(null, dataArray)
			}
		}
	}
} catch (e) {
	this.onError(e)
}
//console.log(this.xhr, data);
if (null != data) {
	this.onData(data)
}

};

"Trying to get property of non-object"

I run a modified web-msg-sender instance on my server, today it threw the following error and stop working:

Trying to get property of non-object in ***/vendor/workerman/phpsocket.io/src/Engine/Socket.php:40

I think it is due to phpsocket.io but not my modification.I cannot reproduce the bug again, it is accidental.

The examle doesnt works for me

Sorry, but the example doesnt works for me.
The default path to the autoloader file is wrong.
If i change it i get this error:
Call to undefined function
Workerman\Lib\pcntl_signal() in .........\Lib\Timer.php on line 56

socket not responding after sometime

I am running auction script through this but after running 12 hour got no response i have to use server.php start command again and again what is solution for this

<?php
use Workerman\Worker;
use Workerman\WebServer;
use Workerman\Autoloader;
use PHPSocketIO\SocketIO;

// composer autoload
include __DIR__ . '/vendor/autoload.php';
include __DIR__ . '/src/autoload.php';


require_once 'app/Mage.php';
//umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));




$io = new SocketIO(2020);


$io->on('connection', function($socket){
     $socket->addedUser = false;
     // when the client emits 'new bid', this listens and executes
      $socket->on('bid', function ($postdata)use($socket){
      Mage::getSingleton('core/session', array('name' => 'frontend'));
      $latency= ping(Mage::getBaseUrl(), 80, 10);
  }

}


$web = new WebServer('http://0.0.0.0:2022');
$web->addRoot('localhost', __DIR__ . '/public');

Worker::runAll();

here is my server.php status

Workerman[server.php] status
---------------------------------------GLOBAL STATUS--------------------------------------------
Workerman version:3.3.3 PHP version:5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1
start time:2017-01-10 16:06:07 run 1 days 19 hours
load average: 0.28, 0.35, 0.31 event-loop:select
2 workers 2 processes
worker_name exit_status exit_count
PHPSocketIO 0 0
WebServer 0 0
---------------------------------------PROCESS STATUS-------------------------------------------
pid memory listening worker_name connections total_request send_fail throw_exception
23921 14.5M socketIO://0.0.0.0:2020 PHPSocketIO 0 38046 0 0
23922 7M http://0.0.0.0:2022 WebServer 0 0 0 0

can you give any solution on that?

HHVM

Hello,

i have tried to run a server with HHVM (5.6.99-hhvm, 3.11.1), but i get this error,

Fatal error: Call to undefined function Workerman\Connection\stream_set_read_buffer() in /var/www/share/app/vendor/workerman/workerman/Connection/TcpConnection.php on line 214
WORKER EXIT UNEXPECTED
worker[PHPSocketIO:4942] exit with status 65280

This error shows only if a client connects to a server.

But Workermen supported HHVM, or?

failed to open stream: No such file or directory

hello Walkor! i'm using XAMPP 5.5.34 on Mac and run your example -> error:
Warning: include(/Applications/XAMPP/xamppfiles/htdocs/_TestChat/phpsocket/examples/chat/../../vendor/autoload.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/_TestChat/phpsocket/examples/chat/server.php on line 8

Warning: include(): Failed opening '/Applications/XAMPP/xamppfiles/htdocs/_TestChat/phpsocket/examples/chat/../../vendor/autoload.php' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/_TestChat/phpsocket/examples/chat/server.php on line 8

Fatal error: Class 'Workerman\Worker' not found in /Applications/XAMPP/xamppfiles/htdocs/_TestChat/phpsocket/src/SocketIO.php on line 28

sorry for my English!

如何让server.php接收get参数

我想让server.php接收get参数,然后传给客户端,不知道如何操作。下面这种方式是不行的

use Workerman\Worker;
use PHPSocketIO\SocketIO;

// composer autoload
include __DIR__ . '/vendor/autoload.php';

$io = new SocketIO(2021);

// 当有客户端连接时
$io->on('connection', function($connection)use($io){
    // 定义chat message事件回调函数
//    $connection->on('chat message', function($msg)use($io){
        // 触发所有客户端定义的chat message from server事件
        $io->emit('chat message', $_GET['key']);
//    });
});

Worker::runAll();

image

如何在server.php中同时监听http请求?

怎样在server.php中监听http请求,当接收到http请求时触发对浏览器client的emit事件?

这样写貌似不可以

$io = new SocketIO(2020);
$io->on('connection', function($connection)use($io,$http_worker){
$connection->emit('server start', '服务器已启动');
echo date('Y-m-d H:i:s')." | ".'Linked'."\n";

$http_worker->onMessage = function($conn, $data)use($connection)
{
    echo date('Y-m-d H:i:s')." | ".'Http'."\n";
    $connection->emit('server msg', '服务器发送消息'.date('Y-m-d H:i:s'));
};

$connection->on('disconnect', function () {
    echo date('Y-m-d H:i:s')." | ".'Lost'."\n";
});

});

其中$http_worker是已经实例化的http类型workmen对象

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.