Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Heroku PHP Refuses more than one query

20 views
Skip to first unread message

k.j.a...@gmail.com

unread,
Mar 15, 2015, 1:07:09 AM3/15/15
to
I've setup my index.PHP file in Heroku to query the database four (4) distinct times and two (2) update queries during the authenticateUser action. However, from the XML result, it appears that only the first query is completed and then the remainder are ignored thus creating a truncated XML result and without even the closing </data> tag.

I believe Heroku is able handle this action as it is not too complex and worked with XAMPP on my local computer and Google Compute Engine without any modifications required. The error log simply notes SET: not found without reporting a line

Why would Heroku only allow the completion of the first query, then terminate the remainder of the action?

How can I make this work?

index.PHP file (authenticateUser action):

case "authenticateUser":
// and return friends and messages

if ($userId = authenticateUser($db, $username, $password))
{

// providerId and requestId is Id of a friend pair,
// providerId is the Id of making first friend request
// requestId is the Id of the friend approved the friend request made by providerId

// fetching friends,
// left join expression is a bit different,
// it is required to fetch the friend, not the users itself

$sqlFriends = "select u.Id, u.username, (NOW()-u.authenticationTime) as authenticateTimeDifference, u.IP,
f.providerId, f.requestId, f.status, u.port
from friends f
left join users u on
u.Id = if ( f.providerId = ".$userId.", f.requestId, f.providerId )
where (f.providerId = ".$userId." and f.status=".USER_APPROVED.") or
f.requestId = ".$userId." ";

//$sqlmessage = "SELECT * FROM `messages` WHERE `touid` = ".$userId." AND `read` = 0 LIMIT 0, 30 ";

$sqlIndMessage = "SELECT m.id, m.fromuid, m.touid, m.sentdt, m.read, m.readdt, m.messagetext, u.username, m.shared_campaign_id, m.shared_campaign_location_id from messages m \n"
. "left join users u on u.Id = m.fromuid WHERE `touid` = ".$userId." AND `read` = 0 LIMIT 0, 30 ";

// Queries for selecting groups and group chats
// Selecting list of groups
$sqlGroups = "SELECT groupId, groupName
FROM users_groups
WHERE usersId = ".$userId." ";

// Get group messages related to that users group, note: even if didn't send any messages as all
// will need all messages related to that group and the user name of the user sending them
// finally: even if not a friend of a group memeber, can still get the messages they send

/*
$sqlGroupMessages = "SELECT gm.id, usr.username as 'fromUser', gm.fromUId, gm.toGroupId, gm.sentdt, gm.read, gm.readdt, gm.messageText
FROM group_messages gm
left join users usr on gm.fromUId = usr.Id
WHERE gm.toGroupId IN (SELECT groupId
FROM users_groups
WHERE usersId = ".$userId.") AND `read` = 0 LIMIT 0, 30";
*/

// Because if not in the group/no messages sent to them , should be empty
$sqlGroupMessages = "SELECT id, myId, fromUser, fromUId, toGroupName, toGroupId, sentdt, `read`, readdt, messageText, shared_campaign_id, shared_campaign_location_id
FROM group_messages
WHERE myId = ".$userId." AND `read` = 0 LIMIT 0, 30";

// Test setting the textsize to a large number:
$txtSize = "SET TEXTSIZE 3000";
exec($txtSize);

if ($result = $db->query($sqlFriends))
{
$out .= "<data>";
$out .= "<user userKey='".$userId."' />";
while ($row = $result->fetch_object())
{
$status = "offline";
if (((int)$row->status) == USER_UNAPPROVED)
{
$status = "unApproved";
}
else if (((int)$row->authenticateTimeDifference) < TIME_INTERVAL_FOR_USER_STATUS)
{
$status = "online";

}
$out .= "<friend username = '".$row->username."' status='".$status."' IP='".$row->IP."' userKey = '".$row->Id."' port='".$row->port."'/>";

// to increase security, we need to change userKey periodically and pay more attention
// receiving message and sending message

} // Getting the individual messages
if ($resultmessage = $db->query($sqlIndMessage))
{
while ($rowmessage = $resultmessage->fetch_object())
{
$out .= "<message from='".$rowmessage->username."' sendt='".$rowmessage->sentdt."' text='".$rowmessage->messagetext."' shared_campaign_id='".$rowmessage->shared_campaign_id."' shared_campaign_location_id='".$rowmessage->shared_campaign_location_id."' />";
$sqlendmsg = "UPDATE `messages` SET `read` = 1, `readdt` = '".DATE("Y-m-d H:i")."' WHERE `messages`.`id` = ".$rowmessage->id.";";
$db->query($sqlendmsg);
}
}

// Get the groups
if ($resultGroup = $db->query($sqlGroups))
{
while ($rowGroup = $resultGroup->fetch_object())
{
$out .= "<groups groupName = '".$rowGroup->groupName."' groupId = '".$rowGroup->groupId."' />";
}

// Get Group messages
if ($resultGroupMessage = $db->query($sqlGroupMessages))
{
while ($rowGroupMessage = $resultGroupMessage->fetch_object())
{
$out .= "<group_message fromUser='".$rowGroupMessage->fromUser."' fromUId='".$rowGroupMessage->fromUId."' toGroupName = '".$rowGroupMessage->toGroupName."' toGroupId = '".$rowGroupMessage->toGroupId."'
sentdt = '".$rowGroupMessage->sentdt."' messageText='".$rowGroupMessage->messageText."' shared_campaign_id='".$rowGroupMessage->shared_campaign_id."' shared_campaign_location_id='".$rowGroupMessage->shared_campaign_location_id."' />";
$sqlGroupEndMsg = "UPDATE `group_messages` SET `read` = 1, `readdt` = NOW() WHERE `group_messages`.`id` = ".$rowGroupMessage->id.";";
$db->query($sqlGroupEndMsg);
}
}


error_log($out, 0);
$out .= "</data>";


}

}
else
{
error_log($out, 0);
$out = FAILED;
}
}
else
{
// exit application if not authenticated user
error_log($out, 0);
$out = FAILED;
}

break;

Jerry Stuckle

unread,
Mar 15, 2015, 8:26:31 AM3/15/15
to
On 3/15/2015 1:07 AM, k.j.a...@gmail.com wrote:
> I've setup my index.PHP file in Heroku to query the database four (4) distinct times and two (2) update queries during the authenticateUser action. However, from the XML result, it appears that only the first query is completed and then the remainder are ignored thus creating a truncated XML result and without even the closing </data> tag.
>
> I believe Heroku is able handle this action as it is not too complex and worked with XAMPP on my local computer and Google Compute Engine without any modifications required. The error log simply notes SET: not found without reporting a line
>
> Why would Heroku only allow the completion of the first query, then terminate the remainder of the action?
>
> How can I make this work?
>

Responded to in comp.lang.php.

Please do not multipost; if you must post to multiple newsgroups, please
crosspost.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

robamm...@hotmail.com

unread,
Mar 16, 2020, 7:30:43 AM3/16/20
to
Probably some server overloading...


Kristjan Robam
0 new messages