Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

One server implemented in PHP to accept connections using ssl:// tcp:// ws:// wss://

License

NotificationsYou must be signed in to change notification settings

napengam/phpWebSocketServer

Repository files navigation

NO DEPENDENCIES

Server written in PHP to handle connections via websocksetswss:// or ws://
and normal sockets overssl://

  • 2025-13-07 refactored

  • 2021-09-30 fixed ping/pong cycle to clients. $pingInterval to start pinging clients

  • 2021-09-28 echo back to client implemented

  • 2021-09-25 php script nac now talk to other script

  • 2021-??-?? Runtime parameters are now read from file specified with option
    -i <inifile> ; default is websock.ini in server directory

  • 2021-08-22 Server and client can now handle very long messages (>8192B)
    no longer need to use own buffer mechanism.

  • 2020-12-07 it works also with PHP 8.0

A detailed documentation is located here:

NO DEPENDENCIES

implemented by

WebSocketServer is based on the implementation in PHP by

The idea of *application classes' is taken from

See alsohttps://tools.ietf.org/html/rfc6455

What is it good for ?

This server allows you to establish communication between web applications living in a browser
and enables backend scripts, in my case PHP, to communicate information back to web applications thathave called the backend script to perform some action.

Clients receive a UUID from the server upon connection. If the web application triggers
backend scripts via AJAX it passes the UUID to the backend scripts. The script is now able to report
back to the web client by sending the UUID along with an opcode 'feedback' and other parameters to the server.
With the given UUID the server now knows to what web client to send the message. Loop closed !

See example in directory webClient

Installation

  • Transfer the directorphpWebSocketServer to the documents root of your webserver

Configuration

Part 1

  • Step into theconfig directory and adapt the
  • websock_exmaple.ini to your needs, rename or copy to websock.ini
    You will find some documentation in this file.

Part 2

To start and use the server see theREADME in directory server

Directories

include

Files included by server and clients

Server

Implemention of a server in php and php script to start server.
Examples of classes to implement resources/php and/web

phpClient

Example of client written in PHP to connect and write to the server using resource/php

php2php

Example how to make one php script send messages to other php scriptvia websocket

webClient

Example of web client to connect and communicate with the server using resource/web

websocketExtern

Conneting to external websocket servers to test client code

Some Numbers

  • Number of Files

  • 'php' => int 24

  • 'js' => int 2

  • Number of Lines of Code

  • 'php' => int 1950

  • 'js' => int 313

  • Size in KBytes

  • 'php' => float 59

  • 'js' => float 10

About

One server implemented in PHP to accept connections using ssl:// tcp:// ws:// wss://

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp