How to organize the exchange of data between PHP applications?

Hi all!

We need to organize the data exchange between the two PHP applications, requests sooo much (100 RPS), and their volume is very small - it is important to organize it so that would work at the speed of light.

In General, there are two PHP application - you need to give them a super fast exchange of small commands, like go; stop; read and etc.

now it is all implemented next using a normal http get, can anyone have ideas how to speed it up?

Annex 1 is based on Windows running PHP script from the command line, which looped request command:

//Ciklum infinity
while (true){

 //Ciklum to receiving the command
 while (!$command){

 //the requested command
$command=file_get_contents("http://site.com/command.php");
}

 //handle command
if(command=="get_app_status"){

 ....... do some kind of action corresponds to the command (read txt file)
$result=$text;

 //return the result
 echo $result;

}

}


Thanks in advance!
June 10th 19 at 15:29
3 answers
June 10th 19 at 15:31
Well, you could open a socket to the daemon and listen to it, and from the second application, respectively, the connection to quit.
It is certainly faster than using the web server via http to handle.
June 10th 19 at 15:33
Alternatively, you can implement the service for message Queuing.

Gearman for example.
Yes, there are the normal radish can - Patricia_Konopels commented on June 10th 19 at 15:36
June 10th 19 at 15:35
There is a great implementation of the sockets Protocol support in PHP WAMP - Ratchet. Detailed documentation on this website
And now a prescription from the practice:
1. Collect simple app with composer, we will need the package cboden/ratchet
2. Write the base class
<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Msg implements MessageComponentInterface {
 public function onOpen(ConnectionInterface $conn) {
}

 public function onMessage(ConnectionInterface $from, $msg) {
}

 public function onClose(ConnectionInterface $conn) {
}

 public function onError(ConnectionInterface $conn, \Exception $e) {
}
}</property-->
<br / > The four defined in the code of the function required, they are designed to handle the appropriate events.<br> 3. PHP-CLI script that starts the server socket and will accept messages:<br> msg-server.php br><pre><code class="php"><?php use Ratchet\Server\IoServer; use MyApp\Msg; require dirname(__DIR__) . '/vendor/autoload.php'; $server = IoServer::factory( new Msg(), 8080 ); $server--->run();</code></pre><br> If you run this file by executing the command<br><code class="bash">php bin/msg-server.php</code><br> The server will work and it can even connect using telnet<br><code class="bash">telnet localhost 8080</code><br><br> 4. The client part package of ratchet/pawl<br> 5. Example implementation:<br><pre><code class="php"><?php require __DIR__ . '/vendor/autoload.php'; \Ratchet\Client\connect('ws://192.168.1.100:8080')--->then(function($conn) { $conn->on('message', function($msg) use ($conn) { echo "Received: {$msg}\n"; $conn->close(); }); $conn->send('Hello World!'); }, function ($e) { echo "Could not connect: {$e->getMessage()}\n"; });</code></pre><br><br> For the transmission of structured data you can use the traditional JSON

Find more questions by tags PHPJSONData exchange