Download the PHP package naivic/oswserver without Composer

On this page you can find all versions of the php package naivic/oswserver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package oswserver

Naivic\OswServer

Example: Two HTML pages from two servers, talks each other

Installation and preparation

  1. Go example/host
  2. Do 'composer update'
  3. Go example (cd ..)
  4. Do 'docker-compose up -d --build'
  5. Open three tabs in browser - one for Alice and two for Bob:

Test and use

On the Alice's tab, type 'Alice' in the field 'Your name', type 'hello' in textarea below, and press [enter].

You will see your message in log on Alice's tab as 'Message from me', and on both Bob's tabs as 'Message from Alice'.

Also you will see server's message "The message has been sent to 2 client connections" on the Alice's tab.

Switch to one of Bob's tab, type 'Bob' in the field 'Your name', type 'hello' in textarea below, and press [enter].

You will see your message in log on both Bob's tabs, and in log on tab of Alice.

You can also test connection/disconnection situations by stopping/restarting containers and closing/reopening browser tabs.

You can monitor the message flow through the osw1 and osw2 container logs.

Basic use case of OswServer

0. See the code example

Refer to the code in /example/host at all stages, it really helps.

1. Design a gRPC service

We need to describe our gRPC service and messages in .proto format and compile the .proto into PHP classes (for a more detailed explanation, see the gRPC tutorials)

Let's describe a simple symmetric host-to-host protocol. Two servers exchange messages, each message has a sender's nickname and text. That's it.

2. Add code to gRPC service class

We need to write our code in gRPC service class.

Just send a message from gRPC peer to our websocket client.

Note the function $serv->sendMsgToClient(), we'll discuss it later.

3. Create main server class

We need to define our main server class, which will do all the work. This class should be a child of \Naivic\OswClass.

4. Define onStart() method to get IP address of peer

We can define an onStart method if we want to do some additional initialization. Here we get the peer IP address from the environment variable.

5. Add code to route messages from peer to client

We need a method to deliver a message from a peer to our client - sendMsgToClient(), mentioned in our function OpenSwoole\GRPC\HostService::Message().

6. Add code to handle HTTP and Websocket requests

We need to define our processing methods:

For example, make loading of the root html page. Refer to the file /example/host/root.html to see client part of code.

Add a method to handle a message from a client. We share messages and delivery statuses across all client connections on a same server.

7. (Optional) Add code to custom gRPC processing and manage Websocket client connections

If we want make some custom processing of gRPC requests - we can add the optional processRequestGrpc() method.

And we can add some code to manage client connections.

8. Start main server

We start our server in usual \OpenSwoole\GRPC\Server manner.

It is not necessary to open different ports for gRPC and WebSocket/HTTP connections. But, if you want, you can easily do it:

9. Add spices to taste

You can easily extend this code to achieve your own goals. Good Luck!


All versions of oswserver with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package naivic/oswserver contains the following files

Loading the files please wait ...