我在Heroku中设置了index.PHP
文件,在authenticateUser
操作期间查询数据库四(4)次不同时间和两(2)次更新查询。但是,从XML结果来看,似乎只完成了第一个查询,然后忽略了其余部分,从而创建了截断的XML结果,甚至没有关闭</data>
标记。
我相信Heroku能够处理这个动作,因为它不太复杂,并且在我的本地计算机和Google Compute Engine上使用XAMPP而无需任何修改。
为什么Heroku只允许完成第一个查询,然后终止操作的其余部分?
我该如何做到这一点?
index.PHP文件(authenticateUser操作):
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;
更新错误日志只记录SET: not found
而不报告一行: