codeboy89 Posted July 6, 2010 Share Posted July 6, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/ Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1081676 Share on other sites More sharing options...
codeboy89 Posted July 6, 2010 Author Share Posted July 6, 2010 premiso, i tried moving $read before $lock but it didn't solve the problem. i'm still getting the same error over and over in the log. Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1081702 Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1081706 Share on other sites More sharing options...
codeboy89 Posted July 6, 2010 Author Share Posted July 6, 2010 yes that is still producing the error, and no the file is not deleted, i am adding some input text then closing it out with fclose. i just keep logging error_log entries on the fread line?? Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1081712 Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1081713 Share on other sites More sharing options...
codeboy89 Posted July 6, 2010 Author Share Posted July 6, 2010 can you show me how to properly setup file_get_contents() with parameters in my situation. i am very new still... Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1082181 Share on other sites More sharing options...
premiso Posted July 6, 2010 Share Posted July 6, 2010 $file = "bb.xml"; $read = file_get_contents($file); Simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1082186 Share on other sites More sharing options...
codeboy89 Posted July 7, 2010 Author Share Posted July 7, 2010 thanks for your help premiso, this solved the problem.. $file = "bb.xml"; $read = file_get_contents($file); $open = fopen($file, "r+"); $lock = flock($open, LOCK_EX); no more annoying flooded error_logs popping up Quote Link to comment https://forums.phpfreaks.com/topic/206826-not-sure-why-this-code-is-creating-error_log/#findComment-1082202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.