[Clipart] PHP and the command line...

Nathan Eady eady at galion.lib.oh.us
Wed Apr 27 10:32:39 PDT 2005


Jon Phillips wrote:

>>Well, the problem here would be that then it'd become a web-only app...
> 
> This is an incorrect assumption. PHP can be run from the commandline
> just like PERL.

I've heard this before, read about it, et cetera, but I've never been
able to make it work.  For instance, when I looked into this possibility
before, I found this article:
http://www.sitepoint.com/article/php-command-line-1

But I wasn't able to get it to work on the fdo server.  I don't
recall now the details of why it didn't work, and I can't shell
into the server from here to check, and I can't seem to get into
my home system ATM (probably the ppp link is down)...

If we could get this working, it would be advantageous for the various
Perl things on the site that get content from shell.php, as they could
skip going through LWP/Apache for that.  (It might even obviate the
need for the cacheing.)  Last time I asked about this on this list,
someone posted PHP code for calling an external script (e.g., a Perl
script), but nobody ever posted how to do the reverse.

You know, it just occurred to me that the cgi server here at work
has PHP installed, even though we've never used it, because our
webmaster asked about it once, and I installed it; she then proceded
not to use it at all, but it's still there.  So I could test on there...

Say, that seems to work...

----------------------------------------->8 begin transcript
[root at cgi root]# emacs temp.php &
[1] 12663
[root at cgi root]# php temp.php
X-Powered-By: PHP/4.0.6
Content-type: text/html

Hello World!
[1]+  Done                    emacs temp.php
[root at cgi root]# php temp.php > temp.htm
[root at cgi root]# cat temp.htm
X-Powered-By: PHP/4.0.6
Content-type: text/html

Hello World!
[root at cgi root]# cat temp.php
#!/usr/local/bin/php
<?php print "Hello World!\n"; ?>
[root at cgi root]# php -v
4.0.6
[root at cgi root]# emacs temp.pl &
[1] 12689
[root at cgi root]# cat temp.pl
#!/usr/bin/perl

print "Calling PHP...\n";
open PHP, 'php temp.php |';
while (<PHP>) {
   print "PHP says: $_";
}
print "PHP exited.\n";
[1]+  Done                    emacs temp.pl
[root at cgi root]# chmod +x temp.pl
[root at cgi root]# ./tem
temp     temp.pl
[root at cgi root]# ./temp.pl
Calling PHP...
PHP says: X-Powered-By: PHP/4.0.6
PHP says: Content-type: text/html
PHP says:
PHP says: Hello World!
PHP exited.
[root at cgi root]#
----------------------------------------->8 end transcript

Now I don't remember why it wouldn't work on the fdo server,
or whether that was before or after the downtime and migration;
if it was before, it might be irrelevant now.  Maybe I should
look into this again, after the impending release.




More information about the clipart mailing list