473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php://stdin too long?

<?
error_reporting(E_ALL & ~E_NOTICE);
if (@is_file('functions.inc.php'))
require_once('functions.inc.php');
$xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
@file_get_contents('php://stdin'));
$parser = @xml_parser_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) {
foreach ($xmlArray[$i]['attributes'] as $attr =$val) {
foreach (array(&$attr, &$val) as $field) {
$field = str_replace('{', '{', str_replace('}',
'}', $field));
$tclList .= (preg_match('/[\s\t]+/', $field)) ? '{' .
$field . '} ' : "$field ";
}
}
}
echo trim($tclList);
?>

This converts XML that is inputted from stdin (a TCL script will input
the XML-read contents into the PHP script) into a TCL list.

However, the PHP script in question dies if stdin is too long. I don't
exactly know the "maximum length" it could be, if there is one, but I
do know that this scirpt will work with this:
php -q /home/ppowell/web/blah.php
<?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
name="Alabama"></state></usa>

But will fail with this:
php -q /home/ppowell/web/blah.php
<?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
name="Alabama"></state><state id="2" abbrev="AK"
name="Alaska"></state><state id="3" abbrev="AZ"
name="Arizona"></state><state id="4" abbrev="AR"
name="Arkansas"></state><state id="5" abbrev="CA"
name="California"></state><state id="6" abbrev="CO"
name="Colorado"></state><state id="7" abbrev="CT"
name="Connecticut"></state><state id="8" abbrev="DE"
name="Delaware"></state><state id="9" abbrev="DC" name="District of
Columbia"></state></usa>

[nothing is returned, and verifying: $xml = ">"]

Is there an actual size limit or is there something else wrong? Feel
free to play with this script as much as you like.

Thanx
Phil

Dec 2 '06 #1
8 3750
comp.lang.php wrote:
However, the PHP script in question dies if stdin is too long. I
don't exactly know the "maximum length" it could be, if there is one,
but I do know that this scirpt will work with this:
Remove the @ signs and see what errors are actual returned.

JW
Dec 2 '06 #2

Janwillem Borleffs wrote:
comp.lang.php wrote:
However, the PHP script in question dies if stdin is too long. I
don't exactly know the "maximum length" it could be, if there is one,
but I do know that this scirpt will work with this:

Remove the @ signs and see what errors are actual returned.

JW
No errors, no warnings, no notices

Phil

Dec 2 '06 #3
comp.lang.php schreef:
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
Dec 2 '06 #4

Tim Van Wassenhove wrote:
comp.lang.php schreef:
error_reporting(E_ALL & ~E_NOTICE);

ini_set('display_errors', TRUE);
Tried that too, no errors, no warnings, no notices

Dec 2 '06 #5
comp.lang.php wrote:
No errors, no warnings, no notices
I have tried your code and it works just fine; I have tested it with the
long XML message in both one line and seperated with new lines.

What you should do besides removing the @ signes, is increasing the error
reporting level to E_ALL only:

error_reporting(E_ALL);

This will at least throw a notice about an undefined variable (not critical
but sloppy).

You can also remove file_get_contents with the following to test if there's
a problem with this function:

$xml = '';
$fp = fopen('php://stdin', 'r');
while (!feof($fp)) $xml .= fgets($fp, 1024);
fclose($fp);

Most importantly, however, is that you start with a small file which
basically only reads the input and prints it. If this works, you can start
rebuilding the script again in small chunks.
JW
Dec 2 '06 #6

Janwillem Borleffs wrote:
comp.lang.php wrote:
No errors, no warnings, no notices

I have tried your code and it works just fine; I have tested it with the
long XML message in both one line and seperated with new lines.

What you should do besides removing the @ signes, is increasing the error
reporting level to E_ALL only:

error_reporting(E_ALL);

This will at least throw a notice about an undefined variable (not critical
but sloppy).

You can also remove file_get_contents with the following to test if there's
a problem with this function:

$xml = '';
$fp = fopen('php://stdin', 'r');
while (!feof($fp)) $xml .= fgets($fp, 1024);
fclose($fp);

Most importantly, however, is that you start with a small file which
basically only reads the input and prints it. If this works, you can start
rebuilding the script again in small chunks.

It works with a small file, no errors of any kind reported, it's just
that when I get to a certain length in my stdin that it locks up,
again, no errors, no warnings, no notices, absolutely nothing.

But if you want to try for yourself, be my guest:
http://valsignalandet.com/xml/state.xml

That is the XML file; I tried on my PC here at home and it was so
volatile my processor crashed each time I tested with it!! However, I
have a very unstable machine so it should not affect anyone else's in
the same way.

Phil
JW
Dec 3 '06 #7
comp.lang.php wrote:
It works with a small file, no errors of any kind reported, it's just
that when I get to a certain length in my stdin that it locks up,
again, no errors, no warnings, no notices, absolutely nothing.

But if you want to try for yourself, be my guest:
http://valsignalandet.com/xml/state.xml
Looks like you need to do some re-installation, as the file transformed
within a second on both my WinXP machine running PHP 5 and a Linux box
running PHP 4...
JW
Dec 4 '06 #8

Janwillem Borleffs wrote:
comp.lang.php wrote:
It works with a small file, no errors of any kind reported, it's just
that when I get to a certain length in my stdin that it locks up,
again, no errors, no warnings, no notices, absolutely nothing.

But if you want to try for yourself, be my guest:
http://valsignalandet.com/xml/state.xml

Looks like you need to do some re-installation, as the file transformed
within a second on both my WinXP machine running PHP 5 and a Linux box
running PHP 4...
JW
I wish I could but it's beyond my power, it's a shared hosting service,
sorry :(

Thanx though
Phil

Dec 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
6
by: Phil Powell | last post by:
In TCL it would be written this way: I guess what I need is the PHP equivalent of TCL's gets command (see http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl8.0a1/gets.n.html for more...
2
by: comp.lang.php | last post by:
function &getResponse() { /*---------------------------------------------------------------------------------------------- New 7/29/2005: Windows can use STDIN, however, the 'con' input data...
1
by: | last post by:
I want to run PHP scripts from my C++ program. I can run "php -n my_script.php" but I have 2 problems: 1. From my C++ program I want to pass to PHP script a data structure (a C++ map). I think...
2
by: Stelios G. Sfakianakis | last post by:
Hello, I am using php 4.2.2 in Red Hat 9.0 with apache 2.0.40 I try to build a php script that accepts POST requests that contain multimedia data and shoves them in a MySQL database. My problem is...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
0
by: todddeluca | last post by:
I am posting code for calling almost any python function from php, because it seems generally useful. Please feel free to suggest improvements or tell me this has already been done better...
2
by: BDthatsme | last post by:
I can't get any of the various examples of keyboard input to work using command line PHP. I have Windows XP Pro SP 2 and PHP 5.1.6 (cli) (built: Aug 23 2006 16:35:53). I can't find any info...
4
by: pcfreak30 | last post by:
ok, i probably have not been registered here long, but i am no noob. I am very experienced in php, but the php cli is a bit of new territory for me. I am trying to create a simple little script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.