PHP Classes

File: src/examples/sender.php

Recommend this page to a friend!
  Classes of walid laggoune   QPHP   src/examples/sender.php   Download  
File: src/examples/sender.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: QPHP
Exchange messages with a queue server using Swoole
Author: By
Last change:
Date: 2 years ago
Size: 785 bytes
 

Contents

Class file image Download
<?php

$address
= '0.0.0.0';
$port = 15674;

if ((
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
    echo
"socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}

if (
socket_connect($sock, $address, $port) === false) {
    echo
"socket_connect() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}

$i = 0;
// Send simple queue message
socket_write($sock, json_encode(["header" => "QUEUE", "payload" => ["user_id" => 5], "options" => ["channel" => "public"]])." \r\n");
// Send queue with delay in seconds
// socket_write($sock, json_encode(["header" => "QUEUE", "payload" => ["user_id" => 5], "options" => ["channel" => "notifications", "delay" => 5]])." \r\n");
$i++;
echo
"Seneded ".$i." \n";
socket_close($sock);