Connect external php script to mysql of a server codeigniter?

0

I have a XAMPP server on an iMac OSX with a portal developed in codeigniter and would like to integrate mySQL Database with an external script that is currently running via terminal and is not storing anything.

The script is for collecting data from a GPS. Here is the 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)
{
    // Mostra o que recebeu
    date_default_timezone_set('Brazil/East');
    $dataagora = date("d-m-Y H:i:s");
    echo "Data: ".$dataagora;
    echo "\nInput = ".$input;
    $trim = trim($input); // Trim the input, Remove Line Endings and Extra Whitespace.
    //echo "Trim = ".$trim;
    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
    }
}

I have two options:

1 - I transform into a controller and let it run 24hs somehow and connect to the DB through the functions of Codeigniter (more difficult).

2 - I connect it to the codeigniter database and continue running externally via terminal. (Easier)

Does anyone have any suggestions? Thank you.

    
asked by anonymous 20.03.2014 / 12:33

1 answer

1

From what I saw in your sample code you include a php that is a class to be able to use the functionality of it.

You have already thought of turning it into a library on the CI, so it would be integrated with the Framework and use all existing features, including access to this database.

    
26.03.2014 / 14:18