0

Here's the deal. I am trying to read values from a text file that I have logging data from each user on my website. The problem is, the code Im using from here on Stack is causing an infinite loop of errors which is ultimately causing my server to run out of resources.

Im using PHP and here is the code to display the data to my google chart:

$file = 'playerlogs/'.$username.'_balance.txt';

$lines=array();
$fp = fopen($file, "r");
while(!feof($fp))
{
$line = fgets($fp, 4096);
array_push($lines, $line);

}
fclose($fp); 

The error Im getting:

fgets() expects parameter 1 to be resource, boolean given in graph.php on line 44
feof() expects parameter 1 to be resource, boolean given in graph.php on line 42

I am fairly new to PHP so if you could help explain your answer with an example of how the code should look I would really appreciate it.

Daniel
  • 73
  • 1
  • 1
  • 5

1 Answers1

0

check your file path, it looks like the script cant access the file. If the file exists, check on its permissions

Veeru
  • 4,936
  • 2
  • 43
  • 61
  • ahh! the permissions! I didnt think about this! – Daniel Oct 23 '14 at 04:40
  • This is a very common error and a quick google can give you all the answers you need. Anyways, if it helped, mark it as an answer. – Veeru Oct 23 '14 at 04:41
  • `code`if (!$fp) { trigger_error('Failed to allocate resource'); exit; }`code` – Daniel Oct 23 '14 at 04:46
  • That will kill it if it starts looping, my permissions ended up being fine. And I did google this. Got the answer of the code that I used above. Thanks. – Daniel Oct 23 '14 at 04:46