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

Heroku PHP Refuses more than one query

17 views
Skip to first unread message

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

unread,
Mar 15, 2015, 1:01:02 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:48:10 AM3/15/15
to
On 3/15/2015 1:00 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?
>

<snip code>

It's hard telling. I doubt anyone here uses Heroku, and most of us
haven't even heard of it. Your best bet is to ask Heroku support; they
know their product better than anyone else. We also don't have your
database, so have no idea if your SQL is correct or not.

However, some suggestions. Your symptoms generally indicate a fatal
runtime error in your code. Your "SET: not found" is not a PHP message,
but could indicate a problem with your database. Since it works on your
local computer but not another one, I would suggest you look for
differences in the systems, especially your database.

Also: On your production system I recommend you have the following in
your php.ini file:

error_reporting=E_ALL;
display_errors=off;
log_errors=on;
error_log=(absolute path/filename to a log file)

This will also log errors to the indicated file, but not display them.

Note you must restart your webserver after making these changes.

Hopefully this will help you locate your problem.

If you don't have access to the php.ini file and are running Apache, you
can also set these in your .htaccess file.

P.S. Please don't multipost. If you must post to multiple newsgroups,
please crosspost.

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