Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 导致内部服务器错误的iOS应用程序_Php_Objective C_Ios_Crash - Fatal编程技术网

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

Php 导致内部服务器错误的iOS应用程序,php,objective-c,ios,crash,Php,Objective C,Ios,Crash,我有一个很奇怪的问题。我的应用程序导致我的服务器崩溃 我的iOS应用程序使用TFHPPLE解析服务器上php页面的数据。它从页面上抓取一个名字,并检查还有多少时间用于该活动 NSString *URL1 = @"http://alefdev.com/tzedakah/current.php"; NSData *webPage = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat: URL

我有一个很奇怪的问题。我的应用程序导致我的服务器崩溃

我的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>";
}
完整的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脚本没有输出正确的头,因此您会遇到服务器错误。

当您得到500时,服务器日志文件会说什么?另外,你能发布完整的服务器端代码吗?我已经添加了日志条目和php脚本。谢谢你的帮助。计时器不停地响,不停地打新电话。我在应用程序中移动了开始和无效呼叫。我还添加到了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>";
}

}
?>