php脚本崩溃apache

时间:2010-01-13 20:43:32

标签: php apache

此脚本崩溃了apache。我故意删除了网址。任何人都可以看看并提供替代品吗?谢谢!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script language="javascript">
$(document).ready(function ()
        {
            $("#btn_Start").attr("disabled",false);
            setTimeout(function(){Doextract();},2000);
        });

function Doextract()
{
    if($("#stop").val() == "1")
    {
        $("#btn_Start").attr("disabled",true);
        window.location.reload();
    }
}

function stop()
{
    if($("#stop").val() == "1")
    {
        $("#stop").val("0");
        $("#btn_Start").val("Start");
    }
    else
    {
        $("#stop").val("1");
        $("#btn_Start").val("Stop");
        $("#btn_Start").attr("disabled",true);
        window.location.reload();

    }
}
</script>
</head>
<body>
<input type="hidden" value="1" id="stop" />
<input type="button" value="Get citys"  id="btn_Start" onclick="stop();" /></div>
<div id="showResult"></div>

  <?php 
 set_time_limit(0);
ini_set('memory_limit', '-1');
$url = "";
include_once 'simple_html_dom.php'; 
include_once 'conn.php';
$id = $_GET['id'];
$sql = "select * from page_category where category_tag = 0 and city_id = '".$id."' LIMIT 0 , 1";
$rst = mysql_query("$sql",$link);
if($rst > 0)
{
      $details = mysql_fetch_row($rst);
      $cateid = $details[0];
      $count = mysql_num_rows($rst);
        $html = file_get_html($url.$details[3]);
        $sql = "delete from page_data where category_id =".$cateid;
        $rst = mysql_query("$sql",$link);
        foreach ($html->find('input#search-find') as $e)
        {
            $categoryname = $e->value;
        }
        foreach ($html->find('div#toolbar-top') as $e)
        {
            foreach ($e->find('strong') as $c) 
            {
                $temp = split('b',$c->plaintext);
                $total = $temp[0];
                $pages = $total/25;
                //echo $total."<br>";
                //echo $pages;
            }
        }
        $j = 1;
        //echo $pages;
        for($i=1;$i<=ceil($pages);$i+1)
        {
                $urls = $url.$details[3]."?page=".$i;
                //echo $urls;
                $html = file_get_html($urls);
              foreach ($html->find('div.description') as $e)
            {
                $name = "";
                foreach ($e->find('h2') as $c) 
                {
                    $name = $c->plaintext;
                }
                $address = "";
                foreach ($e->find('span.street-address') as $c) 
                {
                    $address = $c->plaintext;
                }
                $locality ="";
                foreach ($e->find('span.locality') as $c) 
                {
                    $locality = $c->plaintext;
                }
                $region ="";
                foreach ($e->find('span.region') as $c) 
                {
                    $region = $c->plaintext;
                }
                $code ="";
                foreach ($e->find('span.postal-code') as $c) 
                {
                    $code = $c->plaintext;
                }
                $tel ="";
                foreach ($e->find('li.number') as $c) 
                {
                    $tel = str_replace('(','',$c->plaintext);
                    $tel1 = str_replace(')','',$tel);
                    $tel2 = str_replace('-','',$tel1);
                    $tel3 = str_replace(' ','',$tel2);

                }
                $email = "";
                foreach ($e->find('a.email') as $c) 
                {
                    $email = str_replace('mailto:','',$c->href);
                }

                $sql="insert into page_data (category_id,name,category,address,city,state,postalcode,telnumber,email) values ";
                $sql.="(".$cateid.",'".$name."','".$categoryname."','".$address."','".$locality."','".$region."','".$code."','".$tel3."','".$email."')";
                    //echo $sql;
                $res = mysql_query("$sql",$link);

            }
        }
        $sql = "update page_category set category_tag = 1 where id ='".$cateid."'";
        //echo $sql;
        $res = mysql_query("$sql",$link) or die(mysql_error());
        echo "Category: \"".$details[2]."\" is done!";
}
else 
{
    echo "All categories are done!";
    //$sql = "update page_city set city_tag = 2 where id =".$id;
    //$rst = mysql_query("$sql",$link);
}

  ?>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

你确定它实际上崩溃了apache并且不仅仅是你脚本中的错误吗?你在显示错误吗?

要显示错误,请将其放在页面顶部:

error_reporting(E_ALL);
ini_set('display_errors', '1');

如果这不起作用,我会继续拿走代码,直到它开始工作,然后慢慢构建它,直到它再次中断。然后,你会知道故障点。

答案 1 :(得分:1)

你能告诉我们崩溃的意思吗?脚本没有完成执行吗? Apache会返回500状态吗?

在一般的实践中,你应该简化/取出可能的代码区域,直到你可以让它中断,这样你就可以找到导致PHP自杀的语句。

例如,取出if块的内容......如果脚本有效,你知道你的问题就在那里。您还可以尝试一些策略性放置的die调用,这将停止执行并执行并在函数调用中打印参数的输出。例如,地点:

die(var_dump($details))

在你打电话$details = mysql_fetch_row($rst);之后

看看MySQL是不是在表现。