iOS 应用程序导致内部服务器错误

发布于 2024-12-03 04:35:08 字数 4685 浏览 0 评论 0原文

我有一个非常奇怪的问题。我的应用程序导致我的服务器陷入疯狂。

我的 iOS 应用程序使用 TFHPPLE 解析服务器上 php 页面的数据。它从页面中获取一个名称,并检查该活动还剩多少时间。

 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;


}    

每 10 秒,它调用服务器,获取所需的信息,并将其放入数组中。如果数组为空,则计时器无效,并出现“重新连接”按钮。 “重新连接”按钮可重新启动计时器。

计时器:

-(void)starttimer{

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

NSLog(@"starttimer called");}

重新启动功能

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

如果失败(空数组)然后重新启动,它会再次尝试从我的服务器获取信息,但不能。整个站点给出内部服务器错误 (500)。

php 脚本获取当前日期

$today = getdate();

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

检查日期:

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

然后回显一些文本并在匹配日期后运行倒计时功能。

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>";
}

错误日志显示:

[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

完整的 php 脚本是:

    <?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 = 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>";
}

}
?>

我的主机 (SiteGround) 说我运行了太多 IMAP 进程,但只有当我尝试通过此应用程序重新连接时,该网站才会崩溃。

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 = 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>";
}

}
?>

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-12-10 04:35:08

有两件事正在发生。首先,您对服务器的调用过多,所以我认为您的计时器失效无法正常工作。其次,您的 PHP 脚本没有输出正确的标头,因此您会收到服务器错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文