473,387 Members | 1,486 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,387 software developers and data experts.

calling php from a cgi script

As a shell script, the following program works as expected.

---------------------------------------
#! /usr/bin/sh

echo '<html><? print 1 ?></html>' | php
---------------------------------------

However, when run as a CGI script, invoking php causes the php
interpreter to load the current file (ie, the sh script), which
obviously is ga ga.

How can I supress this behavior of interpreting the current file when
invoking PHP in a CGI script?

Thanks,
David
Jul 17 '05 #1
4 2811
David Van Horn wrote:
As a shell script, the following program works as expected.

---------------------------------------
#! /usr/bin/sh

echo '<html><? print 1 ?></html>' | php
---------------------------------------

However, when run as a CGI script, invoking php causes the php
interpreter to load the current file (ie, the sh script), which
obviously is ga ga.

How can I supress this behavior of interpreting the current file when
invoking PHP in a CGI script?

Thanks,
David


and what is the reason you would do this? The whole reason for PHP is
to be able to write HTML and include dynamic elements from the OS (sh
MySQL, etc... this is why PHP has a call interface to the os (shell_exec
and backtick operators (``) to call sh from PHP not the other way
around. I could be wrong, but I think you are embarking down a path
that will cause you much grief in the future.

You want to use the proper tool to achieve the results and using sh to
call PHP is asking the server to start another program to do something
the sh CGI script is already doing -- there is no value PHP can add by
using it in this manner. in fact is more complicated

echo '<htm> 1 </html>';

This uses one program to execute the same thing not 2 and is less
resource intensive.

Michael Austin.
Jul 17 '05 #2
On Wed, 23 Jun 2004, Michael Austin wrote:
David Van Horn wrote:
As a shell script, the following program works as expected.

---------------------------------------
#! /usr/bin/sh

echo '<html><? print 1 ?></html>' | php
---------------------------------------

However, when run as a CGI script, invoking php causes the php
interpreter to load the current file (ie, the sh script), which
obviously is ga ga.

How can I supress this behavior of interpreting the current file when
invoking PHP in a CGI script?

Thanks,
David


<clip>

echo '<htm> 1 </html>';

This uses one program to execute the same thing not 2 and is less
resource intensive.


obviously the example is serving as an example and not what this person
really wants to accomplish. short, precise questions should be
welcomed<http://www.catb.org/~esr/faqs/smart-questions.html#volume>.

it seems there doesn't exist an option to shut off PHP's obsession of
acting with such a large ego.

i can't find in the PHP C code where the interpreter decides to behave
differently depending if it is operating in a HTTP/CGI environment or in a
shell environment at a command-line terminal.

i tried creating an environment for PHP with the env command, but this
only keeps PHP from processing the file (for which it gives a "No input
file specified." error), and doesn't keep it from stealing the show and
responding to the HTTP/CGI request on its own. can't PHP tell something
is waiting at the door on standard input (stdin) and proces it?

---
#!/bin/sh

echo 'Content-type: text/plain'
echo ''
echo '<html><?php echo 1; ?></html>' | (env SCRIPT_FILENAME='' php)
---

/a
Jul 17 '05 #3
Aaron S. Hawley wrote:
On Wed, 23 Jun 2004, Michael Austin wrote:

David Van Horn wrote:

As a shell script, the following program works as expected.

---------------------------------------
#! /usr/bin/sh

echo '<html><? print 1 ?></html>' | php
---------------------------------------

However, when run as a CGI script, invoking php causes the php
interpreter to load the current file (ie, the sh script), which
obviously is ga ga.

How can I supress this behavior of interpreting the current file when
invoking PHP in a CGI script?

Thanks,
David


<clip>

echo '<htm> 1 </html>';

This uses one program to execute the same thing not 2 and is less
resource intensive.

obviously the example is serving as an example and not what this person
really wants to accomplish. short, precise questions should be
welcomed<http://www.catb.org/~esr/faqs/smart-questions.html#volume>.

it seems there doesn't exist an option to shut off PHP's obsession of
acting with such a large ego.

i can't find in the PHP C code where the interpreter decides to behave
differently depending if it is operating in a HTTP/CGI environment or in a
shell environment at a command-line terminal.

i tried creating an environment for PHP with the env command, but this
only keeps PHP from processing the file (for which it gives a "No input
file specified." error), and doesn't keep it from stealing the show and
responding to the HTTP/CGI request on its own. can't PHP tell something
is waiting at the door on standard input (stdin) and proces it?

---
#!/bin/sh

echo 'Content-type: text/plain'
echo ''
echo '<html><?php echo 1; ?></html>' | (env SCRIPT_FILENAME='' php)
---

/a

What version are you using, because according to the docs, versions
prior to 4.2.0 could not be used interactively (4.2.0 was experimental
only and 4.3.0 removed the experimental status -- see
http://www.php.net/features.commandline

So, to see where the problem lies, break it down to it's basic parts.

what happens when you type:
php -v
from the command line?

Just because a binary can do things from a web server does not imply
that you can also use it from the command line (CLI) - as you/he are/is
attempting to do.

Quite frankly, you could be opening up a security hole big enough to
drive a semi-truck through... I understood what he was displaying was a
"sample" - and from my perspective, a very inefficient coding practice.
There is no added value of using PHP to do what shell/cgi was already
doing - echoing text back to stdout.
Michael Austin.
Jul 17 '05 #4

On Wed, 23 Jun 2004, Michael Austin wrote:
Aaron S. Hawley wrote:
<clip>

it seems there doesn't exist an option to shut off PHP's obsession of
acting with such a large ego.

i can't find in the PHP C code where the interpreter decides to behave
differently depending if it is operating in a HTTP/CGI environment or in a
shell environment at a command-line terminal.

i tried creating an environment for PHP with the env command, but this
only keeps PHP from processing the file (for which it gives a "No input
file specified." error), and doesn't keep it from stealing the show and
responding to the HTTP/CGI request on its own. can't PHP tell something
is waiting at the door on standard input (stdin) and proces it?

---
#!/bin/sh

echo 'Content-type: text/plain'
echo ''
echo '<html><?php echo 1; ?></html>' | (env SCRIPT_FILENAME='' php)
---

/a

What version are you using, because according to the docs, versions
prior to 4.2.0 could not be used interactively (4.2.0 was experimental
only and 4.3.0 removed the experimental status -- see
http://www.php.net/features.commandline

So, to see where the problem lies, break it down to it's basic parts.


brilliant.
what happens when you type:
php -v
from the command line?
I was running my example in 4.36:

PHP 4.3.6 (cgi) (built: Apr 21 2004 01:44:44)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

So it's still broken.
Just because a binary can do things from a web server does not imply
that you can also use it from the command line (CLI) - as you/he are/is
attempting to do.

<snip>

Jul 17 '05 #5

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

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
2
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the...
8
by: Vinod | last post by:
Hi, I have a problem, i am calling an exe from asp program. Its not working fine. When i execute the exe through the dos program directly i get the desired result. My exe will convert files in...
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
4
by: Miguel Dias Moura | last post by:
Hi, I just uploaded a web site and i am getting an error. I have a script which sends form values to an email using AspNetEmail. The script was working when i was calling the script like...
3
by: Anthony Smith | last post by:
In my php page I am calling a Python cgi. The problem is that originally the Python script was being called directly and it could access the environment variables that were being set. Now since the...
47
by: mukeshrasm | last post by:
Hi I am calling two pages using Ajax Get_Pages.php and Get_Content.php from combo box. Both pages are displayed based on selection from combo box. Main problem is that it is not showing the...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.