symbolic link to hhvm behaving differently than binary - php

Not really a problem. Just curious.
When I run hhvm in cli directly it prints usage. Something that I have to specify php file. But when I run php (which is symbolic link to /usr/bin/hhvm) it just hangs. I have to stop it with ctrl^c. Also when I run a php file, hhvm executes file and returns me to prompt but php executes file and then hangs.
Why would this be happening?
Php works through fast-cgi with nginx with no problems. I think that this is a reason that phpstorm stopped receiving connections from xdebug after I updated hhvm.
P.S. I don't have php installed. Just hhvm and I made link /usr/bin/hhvm -> /usr/bin/php for composer to work.

This is because the HHVM binary is running in PHP mode, where it tries to emulate what the PHP binary does.
In this case, it's not hanging but waiting for input as running php-cli with no arguments causes it to read from stdin, then execute it.

Related

PHP-SOAP Server program shell_exec() restrictions

I am running Centos 8 with Apache and PHP 8.0.7 and all are updated to latest versions.
I can not run shell_exec() from within a SOAP server function to run another PHP script. I confirmed php binary is found and the php script is readable. So I can run shell_exec('cat file.php') but when I try to run shell_exec('php file.php') I get nothing. Nothing is disabled in /etc/php.ini and even if I make a hard or symbolic link to /usr/bin/php it refuses to run. I can not explain why it does not work. I need to do this since there is PHP script I wrote which is a SOAP client to a third party Server who make a query to that service and echoes the XML so that it can be captured by my PHP SOAP Server function with shell_exec().

PHP version supposedly wrong, but seems to be correct

I am trying to make a bash script on my server to clear the Grav cache. When I run it from the server, it works fine. But when I run it from my local machine, over SSH, I get an error: You are running PHP 5.6.36, but Grav needs at least PHP 7.1.3 to run. However, php -v on my server returns PHP 7.2.11 (cli) and on my local machine returns PHP 7.1.23 (cli). I do not begin to understand what the problem might be.
In the end, I could not resolve the issue of the different PHP versions, but solved the problem by including the path to the correct PHP version in the server script. So, locally I have ssh jeremygrav#ps589716.dreamhostps.com "bash ./clear.sh" and on the server, the script contains /usr/local/php73/bin/php bin/grav cache --all.
That works fine, although I realise it avoids the problem rather than solving it.

How can I to run php script from powershell-commandline?

How can i setup my powershell to run php scripts in like a commandcall like this
php test.php
I'm able to do this on a server at work which I connect to by putty, but would be nice if I was able to execute those scripts directly from my own without having some server running.
I also know about Xaml, which I don't like since its require you to refresh some browser.
You can do all the stuff suggested above or ...
Go to php.net and download the php file stack for windows.
Copy the file stack into say c:\php or if you want multiple versions, say c:\php5 or c:\php7 etc.
Open powershell and type c:\php\php.exe -h, you will get the php help output. Yay you are up and running, whoot.
(Note: you may need to rename php.ini.development -> php.ini
Advanced instructions:-
Type env into os search (cortana) and select environmental variables.
Add your php location to path (c:\php) and create a variable php (or php5 etc) pointing to c:\php\php.exe
Now you can run php in powershell with php (php -h to test).
Note: while not the question, this also works in the git bash shell.
I'm assuming windows since you said powershell. You can just install php on windows but that means also installing apache or enabling IIS.
Or there's apparently a built-in webserver for command-line functionality that might minimize the amount of headache involved in configuring that stuff.
This might help get you going also:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

PHP Interpreter for Windows

Trying to mess around with PHP, but I don't want to install IIS or Apache and was hoping for a small interpreter that I can pass the scripts to and have them run in like a console or something. Much like Lua does. Does this exist? When I go to download PHP it seems to only talk about running it on IIS or Apache.
PHP can be used on the command line. Just download and extract the executable.
Running can be done 3 ways: a file, supplied code or in an interactive shell
php file.php
php -r "echo 'hello';"
php -a
You can also install a pre-packaged server (e.g. XAMPP) or run your code online on various places (e.g. phpfiddle.org)
With PHP 5.1+ you have an interactive shell too:
launch php with -a parameter
php.exe -a
http://php.net/manual/en/features.commandline.interactive.php
I believe that PHP v5.4 comes with its own webserver built-in. Install that version and you should be fine. Though I really would like to know why you have problem with installing Apache (IIS sucks though).
EDIT:
As a few others have said, you can run PHP from the command line.
check out easyphp, a server for php development
http://php.net/cli
Alternatively, you can write your PHP scripts as you would normally (with some limitations),
And use the following command line:
C:\php.exe -f "D:\phpFile.php"
dtech's answer seems most fitting for the simple script-running things you're looking for. If you decide you want an actual web-server, with as little setup as possible, look at "XAMPP".

How do I find out the currently running PHP executable?

From inside a PHP program I want to know the location of the binary executing it. Perl has $^X for this purpose. Is there an equivalent in PHP?
This is so it can execute a child PHP process using itself (rather than hard code a path or assume "php" is correct).
UPDATE
I'm using lighttpd + FastCGI, not Apache + mod_php. So yes, there is a PHP binary.
eval/include is not a solution because I'm spawning a server which has to live on beyond the request.
Things I've tried and don't work:
$_SERVER['_'] looks like what I want from the command line but its actually from an environment variable set by the shell of the last executed program. When run from a web server this is the web server binary.
which php will not work because the PHP binary is not guaranteed to be the same one as is in the web server's PATH.
Thanks in advance.
The PHP_BINDIR constant gives you the directory where the php binary is
Yeah, $_SERVER['_'] is what you're talking about, or as near as exists. The reason you're getting a Web server binary when it's run from the web is that /usr/bin/php has nothing to do with the Web server's execution; what it's running is a separate SAPI. There's nothing from the web PHP instance to point to /usr/bin/php because there's no reason for there to be.
The PHP_BINDIR constant is probably the easiest thing to use; the next best thing I could come up with is basically re-creating that bindir path from the extension_dir configuration setting:
$phpbin = preg_replace("#/lib(64)?/.*$#", "/bin/php", ini_get("extension_dir"));
It has a regex in it, so it feels more like your native perl(!) but otherwise is not especially optimal.
In PHP5.4 you can use the PHP_BINARY constant, it won't work via mod_php or similar but will via CGI etc.
For earlier versions of PHP readlink('/proc/self/exe'); will probably be fine, again it won't work via mod_php.
Depending on the way php is installed you CANT find the php executable.
if php is running as a module for the webserver like apache module, then there is no binary you can call.
you can take a look into php_info() it lists everything.
may also the path to php. within that path you can assume a php binary.
but why do you want to call a extra process?
you can execute other php files by include command or eval.
there is no reason to spawn a new process.
what about:
<?php
exec("which php");
?>
But, it's unix/linux only:D
I've been looking for the php7 executable on my mac (OSX El Capitan) in order to configure and install xdebug (needed to find the right version of phpize to run). None of the solutions I found worked for me, so I just ended out searching for it:
find / -name php -print
I knew (from phpinfo()) that I was running php7, so I was able to infer the correct directory from the options presented by find.

Categories