Page 1 of 1

PHP CLI Questions

Posted: Thu Aug 31, 2006 9:52 am
by s.dot

Code: Select all

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\HP_Administrator>php
'php' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\HP_Administrator>cd C:\php

C:\php>php -r 'echo "hi";'
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'libeay32.
ll'  in Unknown on line 0
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'ssleay32.
ll'  in Unknown on line 0
PHP Parse error:  syntax error, unexpected $end in Command line code on line 1

Parse error: syntax error, unexpected $end in Command line code on line 1

C:\php>
As you can see, I'm having quite a bit of problems with php command line on windows :P I could do it fine on my unix OS.

#1.. On unix, it doesn't matter what directory I'm in. I can just type "php - r 'some code'" and php will execute it. Can I do this on windows?

#2.. What's up with those PHP Warnings? =/ And how is there a syntax error in the simple echo "hi";?

Sorry if it seems stupid :P

Posted: Thu Aug 31, 2006 9:54 am
by Jenk
You'll need to include the path to the php executable(s) in your Environment Variable "PATH"

(Right click My Computer > Properties > Advanced > Environment Variables > Look for PATH in the second list box and do the obvious)

Posted: Thu Aug 31, 2006 10:02 am
by s.dot
Nice, I was unaware of how to do that. That solved #1.

Code: Select all

C:\Documents and Settings\HP_Administrator>php -r 'echo "hi";'
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'libeay32.d
ll'  in Unknown on line 0
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'ssleay32.d
ll'  in Unknown on line 0
PHP Parse error:  syntax error, unexpected $end in Command line code on line 1

Parse error: syntax error, unexpected $end in Command line code on line 1

C:\Documents and Settings\HP_Administrator>
I think the warnings are due to some files being in the wrong place. Is the parsing error attributed to that?

Posted: Thu Aug 31, 2006 1:27 pm
by Ambush Commander
Specify the ini file.

Posted: Thu Aug 31, 2006 1:40 pm
by feyd
If this is PHP 4, you'll need to use php-cli.exe not php.exe. You may need to move your ini to a better location.. although I've never needed it to be anywhere outside of php's own directory. :?

Posted: Thu Aug 31, 2006 5:34 pm
by s.dot
From googling, I think those are curl libraries. I remember when i set up apache/php/mysql I had no clue what I was doing. So I have copies of my files everywhere. I'm going to do a fresh install on all of them.

Posted: Sat Sep 02, 2006 12:44 pm
by s.dot
I did a fresh install of php, and I'm still having troubles executing code.

Code: Select all

C:\Documents and Settings\HP_Administrator>php -r 'print_r(array(1,2,3));'
PHP Parse error:  parse error, unexpected $end in Command line code on line 1

Parse error: parse error, unexpected $end in Command line code on line 1
:roll:

Posted: Sat Sep 02, 2006 12:47 pm
by Ambush Commander
Well, if it makes you feel any better, I tried running the command and I get the parse error too.

You can always just execute "php" and then type in your PHP code and finish it with ^Z...

Posted: Sat Sep 02, 2006 12:48 pm
by Ambush Commander
Try double-quoting. Works for me when it's " not '. The curious perversions of CMD.EXE...

Posted: Sat Sep 02, 2006 8:11 pm
by s.dot
YUS! Double quoting works. Thanks Ambush.

Posted: Sun Sep 03, 2006 2:05 am
by pedrotuga
scottayy wrote:YUS! Double quoting works. Thanks Ambush.
php tags ( <?php ?> ) should work as well.

feyd...
i took a look at the manual on http://www.php.net/manual/en/install.windows.manual.php...
isnt it the other way around?
like.. php4.exe on php4 and php-cli.exe on php5.
correct me if i am wrong... i never used php cli

Posted: Sun Sep 03, 2006 8:43 am
by feyd
pedrotuga wrote:feyd...
i took a look at the manual on http://www.php.net/manual/en/install.windows.manual.php...
isnt it the other way around?
like.. php4.exe on php4 and php-cli.exe on php5.
correct me if i am wrong... i never used php cli
In more recent version, I believe I am correct. I can't recall exactly how it was laid out. If you really want to check, you can download the various archives.

Posted: Sat Oct 14, 2006 12:16 pm
by Yossarian
Despite the good advice above I got tired of trying to type multiline php code into a dos window, so I found this nice utility, its like a scratch pad, write some lines of php, press update, show raw or html in a second window.

http://www.hping.org/phpinteractive

Seems cool.

Still if anyone does know, in w2k to run this from through php.exe:

Code: Select all

c:\>php php -r
"$d = array(1,2,3);
echo $d;"
Well, it'd be great. But that util looks clever.