PHP CLI Questions

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

PHP CLI Questions

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Specify the ini file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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:
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Try double-quoting. Works for me when it's " not '. The curious perversions of CMD.EXE...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

YUS! Double quoting works. Thanks Ambush.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Post 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.
Post Reply