gpt4 book ai didi

php - iOS应用导致内部服务器错误

转载 作者:行者123 更新时间:2023-12-03 17:41:45 24 4
gpt4 key购买 nike

我有一个非常奇怪的问题。我的应用导致我的服务器发狂。

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

 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进程太多,但是只有当我尝试通过此应用程序重新连接时,该站点才会崩溃。

最佳答案

有两件事发生。首先,您收到太多对服务器的调用,因此我认为您的计时器无效无法正常工作。其次,您的PHP脚本未提供正确的 header ,因此您会遇到服务器错误。

关于php - iOS应用导致内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7301692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com