写入或读取文件时出现服务器错误

时间:2012-07-02 10:44:23

标签: php apache file

我开发了以下代码:

if (time() - filemtime('current.txt') > 5)
{
$xml = simplexml_load_file("http://live.liveradio.ir:8000/liveradiomp3_48.xspf");
    foreach($xml->children() as $child)
    {
        if ($child->getName() == 'trackList')
        {
            foreach($child as $child2)
            {
                if ($child2->getName() == 'track')
                {
                    foreach($child2 as $child3)
                    {
                        if ($child3->getName() == 'title')
                        {
                            $fp = fopen('current.txt', 'w');
                            fwrite($fp, json_encode(array('data',$child3)));
                            fclose($fp);
                        }
                    }
                }
            }
        }
    }
}
echo (file_get_contents('current.txt'));

但是当我运行它时会显示以下页面:

Server error
The website encountered an error while retrieving http://liveradio.ir/temp.php. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

temp.phpcurrent.txt的许可是777.当我评论以下行时,问题就解决了。

$fp = fopen('current.txt', 'w');
fwrite($fp, json_encode(array('data',$child3)));
fclose($fp);
echo (file_get_contents('current.txt'));

问题出在哪里?此代码在localhost上正常工作。

2 个答案:

答案 0 :(得分:0)

网址已离线。那是你的主要问题;)

答案 1 :(得分:0)

您需要检查在远程服务器配置中是否允许通过此特殊端口8000获取XML。