Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » sockets RSS

sockets

This thread was started by Dorky and has been viewed 468 times, and contains 4 replies, with the last reply made by Dorky.
Post Reply
1
44 points at 77%
Dorky, Freelance Home page   Private message  
Posted January 21 '10 at 04:10 PM
      Posts: 790
i am looking to build a chat box into a site that has a log in system in olace. i have some other posts about this. i have set my mind on ajax input but still looking to streaming output of the flatfile that will hold the processed input. i found that php has sockets but i know very little about sockets. what if the viability of using this to stream a flatfile to the client and what would be needed to get this content to a div? any help would be greatly appreciated as all the tutorials i have read melt my brain.

Advertisement Register for free to hide these ads and participate in discussions!

2
View dcre's reputation
dcre, WDF Noob Home page   Private message  
Posted February 7 '10 at 10:42 PM
      Posts: 3
<?php
function readMyFile(){
$fp=fopen('./textfile.txt','r');
echo 
fread($fp,filesize('./textfile.txt'));
fclose($fp);
}
function 
writeMyFile($str){
$fp=fopen('./textfile.txt','a');
fwrite($fp,$str);
fclose($fp);
}
$message=$_GET['message'];
if(
$message<>NULL){
    
writeMyFile($message);
}else{
    
readMyFile();
}
?>
Make sure the web-server user can write to the 'textfile.txt' file. The script returns the contents of the file by default or appends a users message to the file if a message is sent.
Using a flat-file as a database is very slow compaired to using a MySQL database and is harder to control and update.

3
44 points at 77%
Dorky, Freelance Home page   Private message  
Posted February 8 '10 at 11:49 AM
      Posts: 790
ok but this is not anything to do with sockets and will not render in real time, only per page load will you see the results. it would be pretty childish to build a chat box that has to be refreshed to see the input of each user. and no, flatfiles are not slower then mysql. sql db's are an operating system to their own and must be initialized to start with then php has to send a command to that system then wait for a return of data back to the script. so how are all of those extra steps going to be faster then dynamically displaying a file that stays open under socket control? its not. but thanks for trying.

4
View dcre's reputation
dcre, WDF Noob Home page   Private message  
Posted February 8 '10 at 11:52 AM
      Posts: 3
You said that you was going to use ajax to get the file. That is the same as refreshing the page.

5
44 points at 77%
Dorky, Freelance Home page   Private message  
Posted February 10 '10 at 07:03 PM
      Posts: 790
no dude. i said i was using ajax to submit each comment and using an xml socket allows for on-page data transmission without refreshing(on-page). but i want to use php sockets for the display box.

Post Reply