开发者

iOS app causing internal server error

开发者 https://www.devze.com 2023-04-02 15:11 出处:网络
I\'m having a very strange problem.My app is causing my server to go berserk. My iOS app uses TFHPPLE to parse data from a php page on my server.It grabs a name from the page, and checks how much tim

I'm having a very strange problem. My app is causing my server to go berserk.

My iOS app uses TFHPPLE to parse data from a php page on my server. It grabs a name from the page, and checks how much time remains for that campaign.

 NSString *URL1 = @"http://alefdev.com/tzedakah/current.php";

NSData *webPage = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat: URL1]]];  

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:webPage];    
NSArray *elements = [xpathParser search:@"//name"];  

if([elements count] == 0)
{
    NSLog(@"array is empty");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Cannot connect to server." 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [adupdate invalidate];
    rc.enabled = YES;
    rc.hidden = NO;
}
else{

    TFHppleElement *element = [elements objectAtIndex:0];
    NSString *ttl = [element content];
    NSLog(@"Charity Name:  %@", ttl); 
    todayscharity.text = ttl;


}    

Every 10 seconds, it calls to the server, grabs the info it needs, and puts it into an array. If the array is empty, the timer is invalidated, and a 'Reconnect' button appears. The 'Reconnect' button restarts the timer.

The timer:

-(void)starttimer{

adupdate = [NSTimer scheduledTimerWithTimeInterval:(10.0) target:self      selector:@selector(updateAd) userInfo:nil repeats:YES];

NSLog(@"starttimer called");}

The restart function

- (IBAction)reconnect:(id)sender
{
[self starttimer];
}

If it fails (empty array) and then restarts, it tries again to grab info from my servers, but cannot. The entire site gives a Internal Server Error (500).

The php script gets the current date

$today = getdate();

$todayfull = $today['year'].$today['mon'].$today['mday'];

Checks the date:

if(($todayfull == 201192)||($todayfull == 201193))

Then echoes some text and runs the countdown function after matching the day.

function countdown($year, $month, $day, $hour, $minute)
{
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;

$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

if($minutes_left < 1)
{
echo "<ends>Less than 1 minute</ends>";
}
else{
echo "<ends>".$days_left." day ".$hours_left." hours ".$minutes_left." minutes</ends>";
}

Error Logs show:

[Sun Sep  4 14:01:53 2011] [error] [client 184.100.79.143] File does not exist: /home/alefdev2/public_html/error_500.htm
[Sun Sep  4 14:01:53 2011] [error] [client 184.100.79.143] Premature end of script headers: /home/alefdev2/public_html/tzedakah/current.php
[Sun Sep  4 14:01:43 2011] [error] [client 184.100.79.143] File does not exist: /home/alefdev2/public_html/error_500.htm
[Sun Sep  4 14:01:43 2011] [error] [client 184.100.79.143] Premature end of script headers: /home/alefdev2/public_html/tzedakah/current.php
[Sun Sep  4 14:01:43 2011] [error] [client 184.100.79.143] File does not exist: /home/alefdev2/public_html/error_500.htm
[Sun Sep  4 14:01:43 2011] [error] [client 184.100.79.143] Premature end of script headers: /home/alefdev2/public_html/tzedakah/current.php
[Sun Sep  4 14:00:25 2011] [error] [client 184.100.79.143] File does not exist: /home/alefdev2/public_html/error_500.htm

The full php script is:

    <?php
$today = getdate();
$todayfull = $today['year'].$today['mon'].$today['mday'];
echo "Todayfull: $todayfull";

if(($todayfull == 201192)||($todayfull == 201193))
{
echo "<name>The Lone Soldier Center in memory of Michael Levin</name>
<description>Lone Soldier Center desc.</description>    
";

countdown(2011,9,4,0,0);
}
else if(($todayfull == 201194)||($todayfull == 201195)){

echo "<name>Friends of Itamar</name>
<description>Friends of Itamar desc.</description>  
";

countdown(2011,9,6,0,0);
}

else{
echo "Error:  Could not match dates.";
}
?>

<?php
function countdown($year, $month, $day, $hour, $minute)
{
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
$today = time();

$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;

$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = f开发者_如何学Pythonloor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

if($minutes_left < 1)
{
echo "<ends>Less than 1 minute</ends>";
}
else{
echo "<ends>".$days_left." day ".$hours_left." hours ".$minutes_left." minutes</ends>";
}

}
?>

My host (SiteGround) said that I just had too many IMAP processes running, but the site only ever crashes if I try to reconnect thru this app.


There's two things going on. First, you're getting too many calls to the server, so I think your timer invalidation isn't working right. Second, your PHP script isn't putting out proper header, so you're getting server errors.

0

精彩评论

暂无评论...
验证码 换一张
取 消