Skip to content

fix StatusApplication sessions storage collision with same port but different IP #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow PHP programs to receive websocket events by using Client Class
  • Loading branch information
d.roche committed Nov 13, 2020
commit e060f0c6b7f0ade10df5e6f1728bb57e7551fa87
47 changes: 47 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,53 @@ public function sendData(string $data, string $type = 'text', bool $masked = tru
return true;
}

/**
* wait for data
* added by d.roche@girondenumerique.fr
*
* @param int $timeout ( sec )
* @return bool
*/
public function wait(int $timeout = null): bool
{
if ($this->connected === false) {
trigger_error("Not connected", E_USER_WARNING);
return false;
}
$rsocks = Array($this->socket);
$changed = @stream_select($rsocks, $write = null, $except = null, $timeout);
if ( $changed > 0 ) {
return(true);
} else {
return(false);
}
}

/**
* read data from remote server.
* added by d.roche@girondenumerique.fr
*
* @param int $len
* @return string
*/
public function readData(int $len = 4096): string
{
if ($this->connected === false) {
trigger_error("Not connected", E_USER_WARNING);
return false;
}
$ret = '';

$buffer = fread($this->socket, $len);
if ( ! empty($buffer) ) {
$decbuff = $this->hybi10Decode($buffer);
if ( $decbuff['type'] == "text" ) {
$ret = $decbuff['payload'];
}
}
return $ret;
}

/**
* Connects to a websocket server.
*
Expand Down