# I need dhelp with PHP and IRC

**URL:** https://forum.kirupa.com/t/i-need-dhelp-with-php-and-irc/235423
**Category:** programming
**Created:** [August 10, 2007, 8:47pm UTC](https://forum.kirupa.com/t/i-need-dhelp-with-php-and-irc/235423 "2007-08-10T20:47:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![my3brs](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@my3brs](https://forum.kirupa.com/u/my3brs)
#### Post date: [August 10, 2007, 8:47pm UTC](https://forum.kirupa.com/t/i-need-dhelp-with-php-and-irc/235423/1 "2007-08-10T20:47:29Z")

</div>

Hello Kirupians I have a problem that I would like some help with.

I am making an irc bot out of php that is suppose to grab every new line of text at the end of the file every time the txt file has a new line or a few lines of new text. My problem is everytime new text is added to a file it takes a while for php to get the text to irc. I need it to get input to irc as soon as the text file is updated. I don’t know if I should use Fgets and Fopen for the file or not.  
If anyone knows the problem could you please help me fix it? Thanks

```php

set_time_limit(0); 

$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 

socket_connect($socket,'irc.com',6667);  
socket_write($socket,"USER LWBOT2 For all of you
");   
socket_write($socket,"NICK LWBOT2 
");  
socket_write($socket,"JOIN #LWBOT 
");  

$count = 0; 
$start = 1; 
$file = "echoin.txt"; 
while($data2 = file($file)) { 
    if ($data2 != "") { 
        $dat = $data2[$count]; 
    } 
    $ecex = explode(' ', $dat); 
    if ($ecex[0] == "[JOIN]"){ 
        socket_write($socket, "PRIVMSG #Brandon :".$ecex[1]." has joined the game
"); 
    } 
    if ($ecex[0] == "[QUIT]"){ 
        socket_write($socket, "PRIVMSG #Brandon :".$ecex[1]." has left the game
"); 
    } 
    if ($count < count($data2) && ){ 
        $count++; 
    } 
}  
while($data = socket_read($socket,2046))  
{  
    echo $data; 
    flush(); 
    $ex = explode(' ',$data); 
    if($ex[0] == "PING"){ 
        socket_write($socket, "PONG ".$ex[1]."
"); 
    } 
    if (strtolower($command) == ":!die") { 
        socket_close($socket); 
        die(); 
        exit(); 
    } 
}  

```
