Connect external php script to mysql from a codeigniter server?

Asked

Viewed 611 times

0

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

The script is used to take data from a GPS. It follows 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 - Turn it into a controller and let it run 24hs somehow and connect to the BD by the Codeigniter features (more difficult).

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

Anyone have any suggestions? Thank you.

  • For me it is incredibly confusing your question anyway I will ask some basic questions: you want to plug by socket in an X address, get an answer from it and do something?

  • I’d really like it to be option 2, connect to my XAMPP database (where is codeigniter). Is that possible? Where should I put the file and what are the commands to connect the file to the bank? I know hostname=localhost, database=smb, username=root and password='. What to suggest?

  • So, but that’s exactly what I’m questioning, because you’re saying, "I want to connect it to the codeigniter database" that’s kind of "not there". The IC bank is the IC bank and that’s it. What you really want to do is either make the IC connect to the GPS databtase through the IC (switch between the CI database and the GPS database), or do some GPS operation (through the socket, etc), and record this to the IC. Seriously, you’re confused. If I were you, I would restructure the question and put in a clear way what you have, what you want and in what way.

  • Is that the scenario? You have a CI running on a web server and you have a PHP script running locally on your machine. Do you want to send the results of this PHP script to the BD where the CI is running? If so, you can make a controller in the IC that will have the function of receiving the data and storing in the BD. And your PHP script sends the data to your controller.

1 answer

1


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

Already thought of transforming it into a library in CI, so it would be integrated into the Framework and use all existing resources, including access to this database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.