douchenzhan3050 2017-03-02 06:03
浏览 47
已采纳

无法重新声明功能 - 试图每X秒调用一次函数 - php

I've got a php problem.

I've got a php file that reads data from a .txt file. This works, with this code:

$filename= "deadlines.txt";
$fp = fopen($filename,"r");
$content = fread($fp, filesize($filename));
$rawArray = setRawArray($content);
$epochAndTitleArray = toEpoch($rawArray);

Now, I want to make it so that this stuff is executed every second, not just once at the start. So, I tried to fit it into a function, like this:

$filename= "deadlines.txt";
$fp = 0;
$content = 0;
$rawArray = 0;
$epochAndTitleArray = 0;
function readFile(){
$GLOBALS['fp'] = fopen($GLOBALS['filename'], "r");
$GLOBALS['content'] = fread($GLOBALS['fp'], filesize($GLOBALS['filename']));
$GLOBALS['rawArray'] = setRawArray($GLOBALS['content']);
$GLOBALS['epochAndTitleArray'] = toEpoch($GLOBALS['rawArray']);
}

In this case I'm working with globals, before, I did it without, and also left out the lines before the function itself. This was incorrect I think, so I added the globals.

Now, this doesn't work. It gives me the following error:

Fatal error: Cannot redeclare readFile() in .....on line 28, this line 28 is the line of the closing } at the end of the function.

Can you guys help me in completing this task? Thanks already!

  • 写回答

2条回答 默认 最新

  • dongwen5336 2017-03-02 06:12
    关注

    Rename 'readFile' to another, readfile() is predefined function 'http://php.net/manual/kr/function.readfile.php'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部