0

We've iphone and android apps which are sharing the same php web services. We found the 500 internal server errors on several places on the iphone application.

When we trying to access a web service for the very first time it gives the 500 error. If I tried again at the same time its working without the error. But if I try to access after around 10 minutes later, it'll give the 500 error again.

FYI: We checked the DB connections and they've closed properly.

Below is an sample service script which is giving the error.

<?php
include('JSON.php');
include 'Connection.php';

$handle = fopen('php://input','r');

$jsonInput = fgets($handle);
$decoded = json_decode($jsonInput,true);

$postData = file_get_contents("php://input");
$postData = str_replace('&quot;', '"', $postData);
$post = json_decode($postData,true);

$email = $post['Email'];
$password = $post['Password'];

$sqlstr = mysql_query("SELECT admin_id, CONCAT(`first_name`, ' ', `last_name`) AS admin_name FROM admin where email='".$email."' AND password='".$password."'");
$ages = array();

if (mysql_numrows($sqlstr) != 0) {
    $row = mysql_fetch_array($sqlstr);
    $ages [0] = array("output"=>"Success", "userid"=>$row['admin_id'], "username"=>$row['admin_name']);
}
else{
    $ages [0] = array("output"=>"Failed");
}
echo json_encode($ages);
mysql_close($link);
?>

I'm not sure whether this is something like connection timeout or not.

Can it be a error on iphone app?
or php web services?
or the server side error?

We are checking for this more than a week and still unable to find the issue.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Irawana
  • 269
  • 3
  • 6
  • 14
  • A 500 error is a server error. Is there a cookie dropped or something on first visit that would break if it's not there? – zenkaty Oct 16 '12 at 05:51
  • 1
    Do you own the external site, and have you checked the error log on that machine? – Ravi Kant Mishra Oct 16 '12 at 06:05
  • @zenkaty No, this is happening even on the logging service script. Can you check the below URL for the first time, again at the same time and after 10 minutes. You'll see whats the issue. http://resellerservice.delanaapps.com.au/sendLoginDetails.php – Irawana Oct 16 '12 at 07:18
  • Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/KJveJ). See the [*red box*](http://goo.gl/GPmFd)? Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/3gqF9) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/vFWnC). – tereško Oct 16 '12 at 23:15
  • It displays the 500 error every time I visit the page from the address bar. It only displays 'Output: Failed' if I manually REFRESH the page. Not sure if that gives you any insight? – zenkaty Oct 17 '12 at 01:03

1 Answers1

-1

replace

mysql_numrows

with

mysql_num_rows