Issue with blocked socket stream

--=_9894a0ac04b72b409e2df84f1377f2ee
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="UTF-8"

I am trying to open a blocking stream using fsockopen. I want to write and read XML input/output from a server. After opening the steam I will send a XML request to server using the stream. Once this request is sent, I want to keep listening on the port indefinitely.



I tried using blocking stream for this with a huge timeout. But had no success as it was not waiting for such a long period.



Code:

$parser = xml_parser_create("UTF-8");

if($stream = [at] fsockopen($host, $port, $errorno, $errorstr, $timeout)) {

stream_set_blocking($stream, 1);

stream_set_timeout($stream, TIMEOUT);

fwrite($stream, $xml."n");

sleep(2);

while (!feof($stream)) {

$data = fread($stream, 1024);

xml_parse($parser, $data, feof($stream));

}

}



$xml has the xml to be sent. TIMEOUT is set to 3600*24 and $timeout is set to 300. As it is a blocking stream, till the data is not arrived, feof should not happen. But in this case, the stream is not waiting and returning eof. What is the problem with this code?
--=_9894a0ac04b72b409e2df84f1377f2ee--
Phani Raju [ So, 07 Februar 2010 08:06 ] [ ID #2031555 ]

Re: Issue with blocked socket stream

Phani Raju wrote:
> I am trying to open a blocking stream using fsockopen. I want to write and read XML input/output from a server. After opening the steam I will send a XML request to server using the stream. Once this request is sent, I want to keep listening on the port indefinitely.
>
> I tried using blocking stream for this with a huge timeout. But had no success as it was not waiting for such a long period.
>
> Code:
> $parser = xml_parser_create("UTF-8");
> if($stream = [at] fsockopen($host, $port, $errorno, $errorstr, $timeout)) {
> stream_set_blocking($stream, 1);
> stream_set_timeout($stream, TIMEOUT);
> fwrite($stream, $xml."n");

fwrite($stream, $xml."n") should probably be fwrite($stream, $xml."\n") ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Nathan Rixham [ So, 07 Februar 2010 17:06 ] [ ID #2031560 ]

Re: Re: Issue with blocked socket stream

--=_c287b6cfcc81babf4cd7f92afb690044
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="UTF-8"

It was a mistake while copying the code. I had '\n' only.



On Sun, 07 Feb 2010 21:31:55 +0530 wrote

>Phani Raju wrote:



> I am trying to open a blocking stream using fsockopen. I want to write and read XML input/output from a server. After opening the steam I will send a XML request to server using the stream. Once this request is sent, I want to keep listening on the port indefinitely.



>



> I tried using blocking stream for this with a huge timeout. But had no success as it was not waiting for such a long period.



>



> Code:



> $parser = xml_parser_create("UTF-8");



> if($stream = [at] fsockopen($host, $port, $errorno, $errorstr, $timeout)) {



> stream_set_blocking($stream, 1);



> stream_set_timeout($stream, TIMEOUT);



> fwrite($stream, $xml."n");







fwrite($stream, $xml."n") should probably be fwrite($stream, $xml."\n") ?




--=_c287b6cfcc81babf4cd7f92afb690044--
Phani Raju [ Mo, 08 Februar 2010 09:58 ] [ ID #2031639 ]
PHP » gmane.comp.php.general » Issue with blocked socket stream

Vorheriges Thema: simplexml - can it do what I need?
Nächstes Thema: pecl install geoip doesnt work. Warning: opendir(/var/tmp/pear-build-root/install-geoip-1.0.7//var/w