Background Information
I have a function that loops through a list of 3 servers and for each server, it passes a user name and password via SIP message. each SIP server is running the exact same code. It gets the request, and runs an insert statement against a sqlite database.
Problem
Even though the code is the exact same on each server, only 1 out of the 3 is able to update the database. The other two fail when I'm testing the return value of the INSERT statement. The return value is null, for some reason. Here's the lua code that updates the database:
db_connect();
if connected then
sql = "INSERT INTO users(name,password,email_address) VALUES ('"
..name.."','"
..password.."','"
..email_add.."')";
if debug then print(sql); end
retval, emess = conn:execute(sql);
if debug then print("results from insert are:"..retval); end
db_disconnect();
else
emessage = "Unable to connect to db";
end
The system dies on the debug statement that checks retval.
What I've Checked so Far:
The module that triggers all the code above on each server is in PHP... and is just a loop. I'm not doing any multitasking /multithreaded stuff. I just call one server, wait for the response, and then loop to the next, like so:
foreach ($server as $r) {
$api = new PhpSIP('10.1.1.1');
$api->setMethod('CUSTOM-ADD');
$api->setFrom('sip:testserver@testdomain.com');
$api->setUri('sip:'.$r);
$body = json_encode($newuser);
$api->setBody($body);
try {
(string)$sip_response = $api->send();
//sleep(1);
$pattern = "/(201)/i";
if (preg_match($pattern, $sip_response, $matches) ==true) {
$results[$r] = true;
} else {
$results[$r] =false;
}
unset($api);
//sleep(1);
} catch (Exception $e) {
$results[$r] = false;
}//end catch
}//end loop
This code basically opens a socket, and sends a SIP message with a json string containing the user's credentials. Just in case it'd help, I added sleep() in a few different spots but it didn't make a difference.
- I tried to run the lua code on the servers that are failing, manually. it works.
- I tried to copy the INSERT sql statement that is being dumped to the logs and ran it manually on a sqlite command line. It works.
I'm not sure what else to check. if someone has any ideas, i'm all ears. Thanks.
Aucun commentaire:
Enregistrer un commentaire