Nate Posted April 11, 2003 Share Posted April 11, 2003 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. 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. The files are called 'chat.dat' to track what people are saying and 'active.dat' to track the talkative users. 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... I'm very confused...any questions or answers? Quote Link to comment Share on other sites More sharing options...
rayners Posted April 11, 2003 Share Posted April 11, 2003 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... 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. 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. Quote Link to comment Share on other sites More sharing options...
Nate Posted April 11, 2003 Author Share Posted April 11, 2003 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... 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. 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. 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... 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... Nate Quote Link to comment Share on other sites More sharing options...
Nate Posted April 11, 2003 Author Share Posted April 11, 2003 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. 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.... Nate Quote Link to comment Share on other sites More sharing options...
Dorsey Posted November 6, 2003 Share Posted November 6, 2003 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: $fp = fopen( $counterFile, "r+" ) or die( "Can't open counter file [$counterFile]" ); It fails everytime. I know the file exists, although I can't seem to change the permissions from 644, but that's another issue. 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). Thanks, Dorsey Quote Link to comment 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.