douchenzhan3050 2017-03-02 14: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 14:12
    关注

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

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向