John Davidson

php - Sytems running out of memory when Postgresql connection is established

0 comments
Message:


I have built an api that is called 20 times in a second to perform a function that establishes connection to a postgresql but anytime the call is made the system memory gets full. I am a novie in postgresql and any assistance will be appreciated. Below is my php code


try
{
$input=file_get_contents("php://input");
$pgconn = new PgSql();
$selectRecords="SELECT messageid, msisdn, smsmessage, serviceid, isbilled, linkid FROM sdpmtn_mt.smssendingtable WHERE priority = 0 LIMIT 1";
foreach($pgconn->getRows($selectRecords) as $rows){
$msisdn = $rows->msisdn;
$message = $rows->smsmessage;
$serviceid = $rows->serviceid;
$isbilled = $rows->isbilled;
$linkid = $rows->linkid;
$msgid = $rows->messageid;

}
}
catch(Exception $e)
{
print $e->getMessage();
}

I am calling this API twenty times in a second. Please assist with any configurations I have to make.



My Answer:
"php://input");
$data=json_decode($input,true);

$host = 'localhost';
$port = '5432';
$dbname = 'mydatabase';
$user = 'myuser';
$password = 'mypassword';

try {
$pdo = new PDO("pgsql:host=$host;port=$port;dbname=$dbname;user=$user;password=$password");
echo "Connected to database successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}

Rate this post

3 of 5 based on 8979 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us