How to set GET and POST variables through CLI?
How to set GET and POST variables through CLI?
am 22.08.2007 18:23:36 von Steve Francisco
Hi, I'd like to use the command line interface to test my php files
before I put them live. However I can't figure out how to pass
variables so the php program sees them as if they came in via an HTTP
GET request.
For example, if the url would be this on the server:
http://some.server.com/mypage.php?parm1=Hello&parm2=Goodbye
and in mypage.php I do something like this:
$echo $_GET["parm1"];
then how do I test this via the PHP command line?
Am I missing something simple? I tried this but it doesn't work:
php.exe -f mypage.php -- parm1=Hello parm2=Goodbye
Thanks for any help.
-- Steve
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to set GET and POST variables through CLI?
am 22.08.2007 18:53:20 von John Mertic
Any parameters passed from the command line go to the $argv array, but
you cannot specify the key ( they are put in the order in which they
appear ). So calling:
php.exe foo.php "foo1" "foo2"
would call foo.php and $argv would have:
0 => 'foo.php'
1 => 'foo1'
2 => 'foo2'
I suppose you could have something in front of the file that read the
arguments and put them into the $_GET array.
On 8/22/07, Steve Francisco wrote:
> Hi, I'd like to use the command line interface to test my php files
> before I put them live. However I can't figure out how to pass
> variables so the php program sees them as if they came in via an HTTP
> GET request.
>
> For example, if the url would be this on the server:
> http://some.server.com/mypage.php?parm1=Hello&parm2=Goodbye
> and in mypage.php I do something like this:
> $echo $_GET["parm1"];
> then how do I test this via the PHP command line?
>
> Am I missing something simple? I tried this but it doesn't work:
> php.exe -f mypage.php -- parm1=Hello parm2=Goodbye
>
> Thanks for any help.
> -- Steve
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
--
John Mertic "Explaining a joke
is like dissecting a frog: you
jmertic@gmail.com understand it better,
but the frog dies in the
process."
-Mark Twain
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to set GET and POST variables through CLI?
am 24.08.2007 00:52:46 von Steve Francisco
Thanks for your reply John,
Having to add something to the top of my php to get the $_GET array
isn't a great option for me. I want to be able run my php as it would
be run from a web server. Actually I'd also like to integrate it into a
homegrown Java based web server I have, and was going to invoke it by
calling php.exe directly with parameters taken from the HttpRequest. Is
there a better way to integrate php into my mini-server? I don't mind
having to do native calls into a DLL if there's a programming interface
to let me integrate it. I'd prefer a simple call to the .exe and pass
appropriate arguments to set up the $_GET array, but I'll take what I
can get. Is there a better forum for asking about server integration?
-- Steve
John Mertic wrote:
> Any parameters passed from the command line go to the $argv array, but
> you cannot specify the key ( they are put in the order in which they
> appear ). So calling:
>
> php.exe foo.php "foo1" "foo2"
>
> would call foo.php and $argv would have:
>
> 0 => 'foo.php'
> 1 => 'foo1'
> 2 => 'foo2'
>
> I suppose you could have something in front of the file that read the
> arguments and put them into the $_GET array.
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to set GET and POST variables through CLI?
am 24.08.2007 13:45:31 von John Mertic
If your homegrown server supports calling a CGI program to handle
scripts, then you should be able to integrate PHP into it trivially.
You may want to consult the internals list for more details of how
this all works.
On 8/23/07, Steve Francisco wrote:
> Thanks for your reply John,
> Having to add something to the top of my php to get the $_GET array
> isn't a great option for me. I want to be able run my php as it would
> be run from a web server. Actually I'd also like to integrate it into a
> homegrown Java based web server I have, and was going to invoke it by
> calling php.exe directly with parameters taken from the HttpRequest. Is
> there a better way to integrate php into my mini-server? I don't mind
> having to do native calls into a DLL if there's a programming interface
> to let me integrate it. I'd prefer a simple call to the .exe and pass
> appropriate arguments to set up the $_GET array, but I'll take what I
> can get. Is there a better forum for asking about server integration?
> -- Steve
>
> John Mertic wrote:
> > Any parameters passed from the command line go to the $argv array, but
> > you cannot specify the key ( they are put in the order in which they
> > appear ). So calling:
> >
> > php.exe foo.php "foo1" "foo2"
> >
> > would call foo.php and $argv would have:
> >
> > 0 => 'foo.php'
> > 1 => 'foo1'
> > 2 => 'foo2'
> >
> > I suppose you could have something in front of the file that read the
> > arguments and put them into the $_GET array.
> >
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
--
John Mertic "Explaining a joke
is like dissecting a frog: you
jmertic@gmail.com understand it better,
but the frog dies in the
process."
-Mark Twain
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to set GET and POST variables through CLI?
am 24.08.2007 18:23:32 von Steve Francisco
John Mertic wrote:
> If your homegrown server supports calling a CGI program to handle
> scripts, then you should be able to integrate PHP into it trivially.
> You may want to consult the internals list for more details of how
> this all works.
>
Thanks for your help. I did ask on the internals list and found a
solution. I wrote a little php file to convert argv contents into a
$_GET array, put it in my auto_prepend_file setting in php.ini, and now
I just had to convert the html request into arguments to php.exe. It
works wonderfully.
-- Steve
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php