Error Writing/reading Files

liunx

Guest
I've done all the debugging I could possibly do... I have a little chat script written in PHP that I've been playing around with.<br /><br />It works fine on my WinXP box, and on my Linux box, but I've tried it on two different web hosts including my account with TCH and I always get erros when the script tries to read or write to it's files. I could tweak it to use a database, but that would make it harder just to drop into a folder and have it work.<br /><br />The files are called 'chat.dat' to track what people are saying and 'active.dat' to track the talkative users. <br /><br />If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it... When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> <br /><br />I'm very confused...any questions or answers? <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><!--content-->
<!--QuoteBegin-Nate+Apr 11 2003, 11:50 AM--><div class='quotetop'>QUOTE(Nate @ Apr 11 2003, 11:50 AM)</div><div class='quotemain'><!--QuoteEBegin-->If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it...  When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes...  <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br />My initial impression, this sounds to me like its a logic error somewhere in the program. If you can actually write to the file, that has already eliminated any issues you might be having with the system outside of the script.<br /><br />I'd be happy to take a quick look through the script and see if anything jumps out at me if you'd like. I can't promise I'll be able to find the time to do it anytime in the next week or so, but I'll try. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><!--content-->
<!--QuoteBegin-rayners+Apr 11 2003, 12:09 PM--><div class='quotetop'>QUOTE(rayners @ Apr 11 2003, 12:09 PM)</div><div class='quotemain'><!--QuoteEBegin--><!--QuoteBegin-Nate+Apr 11 2003, 11:50 AM--><div class='quotetop'>QUOTE(Nate @ Apr 11 2003, 11:50 AM)</div><div class='quotemain'><!--QuoteEBegin-->If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it...?When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes...?nbsp; <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br />My initial impression, this sounds to me like its a logic error somewhere in the program. If you can actually write to the file, that has already eliminated any issues you might be having with the system outside of the script.<br /><br />I'd be happy to take a quick look through the script and see if anything jumps out at me if you'd like. I can't promise I'll be able to find the time to do it anytime in the next week or so, but I'll try. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> <!--QuoteEnd--></div><!--QuoteEEnd--><br /> Well, it has to be a logic error in the code. Otherwise all the other scripts that write/read files on TCH servers would have the same issues. It just puzzles me that the script works fine on my own boxes... One an WinXP machine running Apache2 and PHP 4.3.1, and the other Slackware 9 running Apache 1.3 with PHP 4.3.1... <br /><br />NEway, I'll keep poking at it. But I may take you up on the offer to look at it if I get too frustrated... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><br /><br />Nate<!--content-->
Yay! Okay, here's the deal. When you open a file in 'a+' mode the file pointer is set to the end of the file, so when I tried to read back from the files I was opening I was ramming my script into a brick wall (past the end of the file). So, I called 'rewind($fp)' before both read operations and it's working now. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><br /><br />Don't ask me why it functions correctly under Slack and Win though...because now that I think about it, it shouldn't at all.... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> <br /><br />Nate<!--content-->
How do you specify the actual file name? I'm trying to use a simple counter file, and have had no success opening the file with:<br /><br /> $fp = fopen( $counterFile, "r+" ) or die( "Can't open counter file [$counterFile]" );<br /><br />It fails everytime. I know the file exists, although I can't seem to change the permissions from 644, but that's another issue.<br /><br /> I've also tried "r", "w", "a", and "a+" options with the exact same result. Do I have to give the full path? I've tried just "counter.txt", "www.ebackbid.com/counter.txt", "/home/ebackbid/public_html/counter.txt" and "public/counter.txt". I'm running out of permutations (and patience).<br /><br />Thanks,<br />Dorsey<!--content-->
 
Back
Top