Jump to content

not sure why this code is creating error_log


codeboy89

Recommended Posts

here is my code to open/read an xml file before posting to it.

 

$file = "bb.xml";
$act = fopen($file, "r+");
$lock = flock($act, LOCK_EX);
$read = fread($act, filesize($file));

 

here is the error_log entry:

 

PHP Warning:  fread() [<a href='function.fread'>function.fread</a>]: Length parameter must be greater than 0 in go.php on line 37

 

can anyone help a newbie solve this problem?  :confused:

 

Well it probably has to do with the path, but not 100% sure (could also be due to the lock).

 

Why not just read it all in with file_get_contents instead before you lock it or get the filesize before you lock it. Either or should work.

This still produces the error:

 

$file = "bb.xml";
$size = filesize($file);
$act = fopen($file, "r+");
$lock = flock($act, LOCK_EX);
$read = fread($act, $size);

 

If it still produces the error, is at any point this file deleted?

do a var_dump on the $size variable. See if the size is coming out.

 

If not, set it to a manual size that it should never hit like (1024*1000) or something. That should cover you.  Or to read it, just do a file_get_contents before the fopen, then you do not have to worry about it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.