lordzardeck Posted April 12, 2009 Share Posted April 12, 2009 How would you go about creating a chat application in php without a database? I know it would involve javascript, I don't really care about code, I just want a concept design. I really can't figure out how. I'm not sure but it might be done by sockets? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/ Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 With a file, consisting of the chat? That's basically what a database is tbh. Why not use a db? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808022 Share on other sites More sharing options...
.josh Posted April 12, 2009 Share Posted April 12, 2009 you would need to use ajax (js) or flash to make it "real time." You would need to store the chat text in a central place so that when someone writes something, it can be displayed for everybody. If you don't want to store the info in a database, your only other option is with a flatfile. With a file, consisting of the chat? That's basically what a database is tbh. Why not use a db? perhaps his hosting does not allow him to have a db? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808027 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Fair enough. I'd guess files would be less secure and reliable though. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808030 Share on other sites More sharing options...
lordzardeck Posted April 12, 2009 Author Share Posted April 12, 2009 Well, actually, my host does give mysql db's but they forbid using for chat. Quite frankly i wouldn't want the load on the server anyways. So there is no way to do that type of app without a db? Even without flat file? The main reason I ask is i'm wanting to make an online game in php and ajax, that works similar to a chat system. I figured learning how a chat system would be made would help me make this game. If it can't be done without a db, I guess I'll just have to use sql lite. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808201 Share on other sites More sharing options...
laffin Posted April 12, 2009 Share Posted April 12, 2009 Use a flatfile, and limit the amount of lines stored in the file its the easiest way. you can put the file off the web folder, so no one can access it or use .htaccess to deny access to that folder If not done this way, u need a full time service in order to keep all the data in memory. php just runs when requested to run, so u need to store the info u get from chat somewhere, when its not being requested. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808209 Share on other sites More sharing options...
lordzardeck Posted April 12, 2009 Author Share Posted April 12, 2009 Okay, I understand that i must use a db like sql lite? Is there any place I can read up on this? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808216 Share on other sites More sharing options...
dewey_witt Posted April 12, 2009 Share Posted April 12, 2009 use a txt file write input to the text file draw input back out of txt file print to frame auto refresh the frame every .2 second disable refresh sound with java script. real time chat with .txt base filing chron job to wipe the file clean every ten minutes or so. most of this you can do with PHP but some things would have to be handled via java like refreshing just the frame and not the whole page. Also java would be needed to go to the end of that doc instead of starting at the beginning. I've actually seen this done 0nce or twice. I'll look for the source and post a link if i find it in a timely manor. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808217 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 An iframe would munch on your bandwidth. You'd be better using ajax. And I wouldn't have a cron job delete old stuff either - it could wipe out a long convo while someone was still talking. I'd go with the .txt file if I were you though, and protect it with .htaccess. And maybe check to see if the file has been modified in the last day or something. If it hasn't; chances are the conversation is over, so you can delete it. That's how I'd do it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808237 Share on other sites More sharing options...
lordzardeck Posted April 13, 2009 Author Share Posted April 13, 2009 Well, any help at any time would be grateful. This is going to be a long and difficult project. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808297 Share on other sites More sharing options...
shlumph Posted April 13, 2009 Share Posted April 13, 2009 I would imagine constantly opening, reading, and deleting a flat file would be a lot more expensive on the server than opening, reading, and deleting rows from a database. But hey, whatever floats your hosts boat Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808310 Share on other sites More sharing options...
lordzardeck Posted April 13, 2009 Author Share Posted April 13, 2009 Yeah, i would rather it be in a mysql db but I have 1&1, so my hosting provider basically sucks. But hey, it's cheap, affordable, and it provides the best options for $5. But sql lite should be okay. Anyone have anyideas where I can read about making a chat app with php and ajax? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808316 Share on other sites More sharing options...
jackpf Posted April 13, 2009 Share Posted April 13, 2009 I don't know, if it's shared hosting and there are multiple sites using the same mysql server, they probably don't want people overloading it with chat applications. It probably would be faster, but if everyone on that server did it, it'd be slow as...something really slow, and overloading all the time. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808319 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 files must be read and parsed when making standard http requests anyways. There's not a whole lot different going on, as far as server load, than a server just reading a file directly on the server. It really boils down to how much coding you have to do to keep track of what's in the file. The overall point of a database is that the data is structured for easier handling so you don't have to write a bunch of code to keep track and parse a file as a whole. But...with a basic chat app...there really isn't all that much to it. You could have it simply append the latest entry to the end no problem. It might actually be more efficient to just use a flatfile for a basic chat app. "Basic" being the keyword, though. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808324 Share on other sites More sharing options...
lordzardeck Posted April 13, 2009 Author Share Posted April 13, 2009 Well in the end, it won't even be a chat app, really. It's going to be a game that would work like a chat app, and I would like a chat feature included. Isn't sql lite just like mysql but as a single file? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808337 Share on other sites More sharing options...
laffin Posted April 13, 2009 Share Posted April 13, 2009 Its a subset of SQL, not like MySQL. But yea SQLite uses a local file no ports to go thru so depending on the read/write ratio it can be faster the MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808339 Share on other sites More sharing options...
lordzardeck Posted April 13, 2009 Author Share Posted April 13, 2009 But doesn't it use the same queries like "SELECT * FROM foo WHERE bar = foo? Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808344 Share on other sites More sharing options...
FaT3oYCG Posted April 13, 2009 Share Posted April 13, 2009 why dont u search for SQLite and find out, google, these forums, the official website, any of the preceding. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808362 Share on other sites More sharing options...
lordzardeck Posted April 13, 2009 Author Share Posted April 13, 2009 Yeah, I should think before I post. Quote Link to comment https://forums.phpfreaks.com/topic/153751-chat-app-without-database/#findComment-808430 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.