473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php://stdin too long?

<?
error_reporting (E_ALL & ~E_NOTICE);
if (@is_file('func tions.inc.php') )
require_once('f unctions.inc.ph p');
$xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
@file_get_conte nts('php://stdin'));
$parser = @xml_parser_cre ate();
@xml_parse_into _struct($parser , $xml, $xmlArray, $tags);
@xml_parser_fre e($parser);
for ($i = 1; $i < @sizeof($xmlArr ay) - 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="Californi a"></state><state id="6" abbrev="CO"
name="Colorado" ></state><state id="7" abbrev="CT"
name="Connectic ut"></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 3772
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('displa y_errors', TRUE);
Dec 2 '06 #4

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

ini_set('displa y_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_conten ts 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_conten ts 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
8802
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 will probably use a hyperlink with a unique ID, but I also want to know how to go about reading from a mailbox with Php so I can use an email reply method, too. I'm having trouble finding any kind of tutorial. From the bit of searching I've done,...
6
24866
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 information) or perhaps the PHP equivalent of how a Java app would read from standard in:
2
1372
by: comp.lang.php | last post by:
function &getResponse() { /*---------------------------------------------------------------------------------------------- New 7/29/2005: Windows can use STDIN, however, the 'con' input data stream, i.e. 'console', is built into DOS functionality and produces a better data input stream result. Use that for Windows. If this stream is not available or if you are using UNIX, you will simply open using STDIN by default
1
1813
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 these solutions: a. Save from C++ program a temp file and load from PHP script b. PHP script stdin passed from my C++ program (I dont know how) c. Link with php5ts.dll (or .so) and pass the data (is it possible?) 2. When PHP script finished, I...
2
7420
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 that it seems that I cannot read the POST data from stdin. I created the following php script to test it: <?php
17
7928
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" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL script can call the PHP
0
1785
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 somewhere else, etc. My limited searching turned up nothing. I work in a heterogeneous environment with php web pages and python modules/scripts. This code requires no no creation of an ad hoc command line interface to the python module and/or ad hoc...
2
11318
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 about why it doesn't work, or a way that does work. Any suggestions? examples of attempted variations: (and I've tried others)
4
2246
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 that will fetch a webpage and save it to a file. This is just for practice for the records. here is my code: <?php fwrite(STDOUT,"Created By Derrick Hammer\n");
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.