Welcome Guest, Not a member yet? Register   Sign In
I have this Socket Server php code and I have to run it as a controller or by a controller?
#1

[eluser]Unknown[/eluser]
Hi. I have some experience with Codeigniter and I need to develop something for a CI server which receives messages from a GPS device in a given IP:port.

The working code is as code follows:

Code:
<?php

require_once("SocketServer.class.php"); // Include the File
$server = new SocketServer("172.17.0.243",20490); // Create a Server binding to the given ip address and listen to port 31337 for connections
$server->max_clients = 10; // Allow no more than 10 people to connect at a time
$server->hook("CONNECT","handle_connect"); // Run handle_connect every time someone connects
$server->hook("INPUT","handle_input"); // Run handle_input whenever text is sent to the server
$server->infinite_loop(); // Run Server Code Until Process is terminated.


function handle_connect($server,$client,$input)
{
    SocketServer::socket_write_smart($client->socket,"OK!");
}
function handle_input($server,$client,$input)
{
    echo "\nInput = ".$input;
    $trim = trim($input); // Trim the input, Remove Line Endings and Extra Whitespace.
    if(strtolower($trim) == "quit") // User Wants to quit the server
    {
        SocketServer::socket_write_smart($client->socket,"Oh... Goodbye..."); // Give the user a sad goodbye message, meany!
        $server->disconnect($client->server_clients_index); // Disconnect this client.
        return; // Ends the function
    }
    //echo $trim;
    //$output = strrev($trim); // Reverse the String
    //echo $output;
    //SocketServer::socket_write_smart($client->socket,$output); // Send the Client back the String
    //SocketServer::socket_write_smart($client->socket,"MAIS",""); // Request Another String
}

It requires the following file:
http://www.phpclasses.org/browse/file/31975.html

This socket server works like a service, I run it via the terminal. Any way to run it 24/7 as a controller or called by another controller? I just need it to store all the input received on a database and that's it.

Any suggestions? Thank you.
#2

[eluser]jonez[/eluser]
http://php.net/manual/en/function.set-time-limit.php set to 0 and make your code run in an infinite loop.




Theme © iAndrew 2016 - Forum software by © MyBB