It looks like you didn't pass in a socket resource as the first parameter to socket_write. http://php.he.net/manual/en/function.socket-write.php > From: chris@xxxxxxxxxxxx > To: instructicc@xxxxxxxxxxx; php-general@xxxxxxxxxxxxx > Date: Mon, 8 Oct 2007 19:51:15 +0100 > Subject: Re: Socket how to die if connection broken > > Hi I got this error > > Warning: socket_write() expects parameter 1 to be resource, null given in > /path/script.php on line 34 > > Thanks > > ----- Original Message ----- > From: "Instruct ICC" <instructicc@xxxxxxxxxxx> > To: <php-general@xxxxxxxxxxxxx> > Sent: Monday, October 08, 2007 7:43 PM > Subject: RE: Socket how to die if connection broken > > > > Remove the @ and see if you get any useful message. > > > From: chris@xxxxxxxxxxxx > > To: stuttle@xxxxxxxxx > > CC: php-general@xxxxxxxxxxxxx > > Date: Mon, 8 Oct 2007 19:04:45 +0100 > > Subject: Re: Socket how to die if connection broken > > > > Hi Stut Ive tried your example but still cant get it to work. > > > > ----- Original Message ----- > > From: "Stut" <stuttle@xxxxxxxxx> > > To: <chris@xxxxxxxxxxxx> > > Cc: <php-general@xxxxxxxxxxxxx> > > Sent: Monday, October 08, 2007 5:26 PM > > Subject: Re: Socket how to die if connection broken > > > > > > > chris@xxxxxxxxxxxx wrote: > > >> Hi I have a socket connection like so.. > > >> > > >> $sourceip = '84.234.18.16'; // ip you want to bind to > > >> > > >> $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); > > >> socket_bind($sock, $sourceip); > > >> socket_connect($sock, 'dac.nic.uk', 2043); > > >> > > >> if ($socket === false) { > > >> $errorcode = socket_last_error(); > > >> $errormsg = socket_strerror($errorcode); > > >> die("Couldn't create socket: [$errorcode] $errormsg"); > > >> } > > >> > > >> > > >> But if the socket connection gets broken it creates an error msg > > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in > > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in > > >> Warning: socket_write(): unable to write to socket [32]: Broken pipe in > > >> > > >> That spills out for thousands and thousands of lines. > > >> > > >> What would I need for the script to die if the connection gets broken. > > > > > > This has nothing to do with opening the socket. When you are writing to > > > the socket you need something like this... > > > > > > if (false === @socket_write($s, $buffer)) > > > { > > > // In here you know something is wrong. Use socket_last_error() to > > > // find out what and deal with it appropriately. Bear in mind that > > > // socket_write can fail for lots of reasons, not just a broken > > > // pipe so you need to check what error occurred before you can > > > // know what to do with it. > > > } > > > > > > Note that you should never use the @ operator unless you are absolutely > > > sure you're handling any potential errors correctly. > > > > > > -Stut > > > > > > -- > > > http://stut.net/ > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > _________________________________________________________________ > Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare! > http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > _________________________________________________________________ Help yourself to FREE treats served up daily at the Messenger Café. Stop by today. http://www.cafemessenger.com/info/info_sweetstuff2.html?ocid=TXT_TAGLM_OctWLtagline