php-general Digest 7 Feb 2010 15:22:26 -0000 Issue 6578
Topics (messages 301856 through 301860):
Problem with blocking streams in PHP
301856 by: Phani Raju
Issue with blocked socket stream
301857 by: Phani Raju
Re: simplexml - can it do what I need?
301858 by: TerryA
301859 by: Carlos Medina
Hi list --- justa simple question
301860 by: ebhakt
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
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 = @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?
I tried using even stream_select but faced same issue.
--- End Message ---
--- Begin Message ---
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 = @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?
--- End Message ---
--- Begin Message ---
Hi Shawn
Thanks for answering my query. I have looked at the suggestions:
$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
I am/was able to load the file OK and to access the data by iteration.
However, I can't find a way to extract data by attributes. I need something
like $string=<element idtype="11" lang="fr" label="Description - Etage">.
Obviously, that won't work but that's the result I need. How do I get the
data out of one of these elements by specifying its idtype and lang? I've
google for hours on this and for another hour on SimpleXMLElement.
Terry
--
View this message in context:
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27486649.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---
--- Begin Message ---
TerryA schrieb:
Hi Shawn
Thanks for answering my query. I have looked at the suggestions:
$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
I am/was able to load the file OK and to access the data by iteration.
However, I can't find a way to extract data by attributes. I need something
like $string=<element idtype="11" lang="fr" label="Description - Etage">.
Obviously, that won't work but that's the result I need. How do I get the
data out of one of these elements by specifying its idtype and lang? I've
google for hours on this and for another hour on SimpleXMLElement.
Terry
Hi Terry,
look at the PHP.NET documentation. There indicates the use of
simpleXMLElement structures. If you want to extract elements from this
object, please read there how this work. By the way, it would be
interesting to see, how your XML is made. May be is usefull to use
another class like DOM.
regards
carlos
http://de2.php.net/manual/fr/book.simplexml.php
http://de2.php.net/manual/fr/refs.xml.php
--- End Message ---
--- Begin Message ---
I am developing a website here wherein i need to post a lot of content.
I am trying to develop a script to post data automatically to the site
the site is designed in drupal
any idea/comment or suggestion on how should i begin with because i am new
to php language
--
Bhaskar Tiwari
GTSE Generalist
Directory Services
Microsoft
\____________________________________________________________
All we have to decide is what to do with the time that has been given to us
bhaskartiw...@officeliveusers.com
http://www.ebhakt.com/
http://fytclub.net/
http://bhaskartiwari.web.officelive.com/
http://ebhakt.spaces.live.com/
--- End Message ---