I am creating a chat API for Android developers, but it's slow -- the chat app is getting messages a little bit late.
How can I improve the performance of my code?
<?php
require_once('config.php');
$sender_id = $_GET['sender_id'];
$receive_id = $_GET['receive_id'];
$response = array();
if($sender_id && $receive_id)
{
$results = mysql_query("select * from cpo_chat_system where (sender_id = '$sender_id' AND receive_id = '$receive_id') union select * from cpo_chat_system where (sender_id = '$receive_id' AND receive_id = '$sender_id') ORDER BY date ASC, time ASC");
$total_record = mysql_num_rows($results);
if($total_record > 0)
{
$response['success'] = '1';
while($row = mysql_fetch_assoc($results))
{
$response['user'][] = $row;
}
}
else
{
$response['success'] = '0';
$response['user']['error'] = "1";
$response['user']['error_msg'] = "Not Data Found";
}
}
echo json_encode($response);
?>
$sender_id = mysql_real_escape_string($_GET['sender_id'];
You can read more about the deprication of mysql here \$\endgroup\$