Zend Server Version? - php

How can I receive the Zend Server version by a PHP script running on this Zend Server?
phpinfo() and the commandline php -v does not tell the Zend Server version!

You cannot derive the Server version from phpinfo (or the environment for that matter).
I assume you are after the values that are displayed in the Server Control GUI at Monitor | Server Info, e.g. version and build. They are stored in in $InstallDir/GUI/application/data/zend-server.ini. Your application has to have access to the folder where the Ini is located, load the Ini file (with something like Zend_Config) and then you can work with the values.
Note that ZS is build with ZF and the files are not obfuscated, so you can check out their source code to see how they access this information. Might very well be possible to reuse some of their code.

A quick and dirty way to get it:
$ cat /usr/local/zend/gui/application/data/zend-server.ini | grep version
Here you would replace /usr/local/zend with whatever alternative path you might have chosen.
And you'll get some output like:
version = 5.6.0

You can use the following command:
echo Zend_Version::VERSION;

Open the zend server .ini file (zs_ui.ini) and find version.
...\Zend\ZendServer\gui\config\zs_ui.ini
Example:
zend_gui.version = 9.0.1

Related

Check if a php script is executed in fpm environment [duplicate]

I use shared hosting.
There is possible to find out whether PHP is running via fastCGI (or maybe CGI) or as Apache module mod_php?
Is it possibly to find out by myself, without asking the hoster?
That's the Server API row on top of phpinfo()'s output:
However, please note that it won't necessarily tell you the exact version of Apache or the exact CGI handler. It just describes the SAPI in use.
You can also call the php_sapi_name() function (or the PHP_SAPI constant, which provides the same info):
Description
string php_sapi_name ( void )
Returns a lowercase string that describes the type of interface (the
Server API, SAPI) that PHP is using. For example, in CLI PHP this
string will be "cli" whereas with Apache it may have several different
values depending on the exact SAPI used
It's still a good idea to check your HSP's documentation because it possible to have several PHP versions available.
Remember you need to run phpinfo() from the same environment you want to check (web server won't tell you about command line and vice-versa):
C:\>php -i | findstr /C:"Server API"
Server API => Command Line Interface
$ php -i | grep 'Server API'
Server API => Command Line Interface
You can use the link below:
How to determine php is running as php cgi or apache module?
or create a file info.php and type
<?php
phpinfo();
?>
now run file with your domain name.
find Server API on file and it show you PHP is running on server with CGI OR Apache
Security consideration: Make sure to delete the file which outputs phpinfo() especially if the website is or is going to be hosted online. The information shown there is a gold mine for hackers.

Zend doesn't load pdo_dblib

I'm trying to connect a Zend application (version 1.11.11) to an mssql server via pdo_dblib (using PHP version 7.0.22). I know that my PHP installation has pdo_dblib since running print(extension_loaded('pdo_dblib')); in the terminal returns 1. In the .ini file I have:
resources.db.adapter = "pdo_mssql"
resources.db.params.pdoType = "pdo_dblib"
When I run the application with a debugger, the value of the statement $a = extension_loaded('pdo_dblib'); is false.
As a result of this PDO::getAvailableDrivers() doesn't contain pdo_dblib (of course), which causes the application to throw an exception.
Does anyone know why this problem occurs, and how to fix it?
The key is not Zend, but in a subtle detail of your tests:
running print(extension_loaded('pdo_dblib')); in the terminal returns 1
when I run the application with a debugger, the value of the statement $a = extension_loaded('pdo_dblib'); is false
PHP on the terminal is not guaranteed to have the same configuration, or even be the same version, as PHP on the web server of the same machine.
You will need to look into your hosting setup to find out how to enable the extension in the php.ini (or equivalent) in the web server's copy of PHP. The output of phpinfo() run in your application, not the terminal, may help.

Use Lampp mysqldump as default in php call

tricky question and I don't know if SO is the good space (maybe AskUbuntu ? or SuperUser ?)
I've set my Lampp on my ubuntu in /opt/lampp/
Problem, when I need to call direct bin as mysqldump, I end up calling the default installed one on my ubuntu, not the one linked to my lampp :
$ mysqldump --user=root test
mysqldump: Got error: 2002: Can't connect
to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
when trying to connect
As you can see, it check for /var/run.
If I want to use the good one, I should specify the path :
$ /opt/lampp/bin/mysqldump --user=root test
-- MySQL dump 10.13 Distrib 5.6.21, for Linux (x86_64)
I could use the full path in my PHP call, but my PHP prod server will then not work.
How can I set the Lampp bin as default to be used by php with exec('mysqldump')?
You really have several choices to do what you want.
You could create a configuration file that depends on your environement (local, dev, preprod, prod ...). This file may declare an array of configurations, one of which is the path of the executable you need. Your php code will know the environment by checking a global variable, for instance $_SERVER, which can be set in your web server's vhost file. I think that's the clean way of doing.
You could hardcode a path for you executable (let's say /home/www/mysqldump) and create a symbolic link with ln -s (if I remember right, or check the man page) between your environment's executable /opt/lampp/bin/mysqldump and /home/www/mysqldump. You have to prepare all your environments that way. I think it's a bit ugly but it's quick.
I am sure there are tons of other solutions.

How to debug PHP CLI scripts from the CLI

Does anybody know how to debug CLI PHP scripts from the CLI?!? I don't want to debug a PHP web page - I don't have a PHP web page. I don't want to debug a remote script either - I'm running/debugging right here on this system. I don't want to (at this time) try to get some IDE (Eclipse, PhpStorm or whatever) to debug a CLI PHP rather I just want to debug some PHP CLI script at the Linux command line itself. In Perl this would be simply perl -d <script.pl> <options>. Debugging a script, to me, is not figuring out compile errors or other simple things. To me it's setting break points, running code, examine the contents of variables and being able to arbitrarily execute or eval ('<php code>') at the debugger.
Sure later I'd like to configure this into my IDE of choice (at this time this is Eclipse) but I have not managed to get that working. Debugging from the CLI a PHP CLI script would be a good start for me.
Thanks.
I don't know why I'm limited to a character count when posting a comment. Perhaps I can add more text here.
Here's what I have tried in order to use xdebug and/or Zend debugger with Eclipse:
Base Eclipse version Mars.1 Release 4.5.
Eclipse PDT UI Plugin version 3.7.0.2015112
Tried installing xdebug using pecl install xdebug. Says I need to add "zend_extension=xdebug.so" to php.ini. Really? Which php.ini? I have several:
Andromeda:sudo find / -xdev -name php.ini
/etc/php5/cli/php.ini
/etc/php5/apache2/php.in
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php53/php.ini
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php.ini
/opt/eclipse/plugins/com.zend.php.debug.debugger.php56.linux.x86_64_13.0.1.v20151112-2045/resources/php56/php.ini
Andromeda:
I put the zend_extension thing in both /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini. Made a phpinfo.php page and I see Xdebug in there (yea!). Configure a Debug Configuration in Eclipse to use xdebug and try to debug:
Launching renameUser has encountered a problem. An internal error occurred during "Launching renameUser" java.lang.NullPointerException.
Oh goodie...
I had also installed the Zend Debugger and added the following to those same two php.ini files:
zend_extension=/usr/lib/php5/20121212/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1/32, 192.168.0.0/16
zend_debugger.expose_remotely=always
Changed debug configuration to use Zend Debugger and attempted to debug. Received:
Error launching 'renameUser' The debug session could not be started. Please make sure that the debugger is properly configured as a php.ini directive.
Restarted Eclipse and now the debugger attempts to run but simply terminates with a 255 exit value attempting to run /opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi. Why it's runnign php-cgi is beyond me. I said this was a CLI not a CGI. In any event I get the following when trying to run this from the command line:
Andromeda:/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
Found a libiconv.so.2 in /opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/lib and set LD_LIBRARY_PATH to include that but this just fails to launch the debugger at all stating to make sure that the debugger is properly configured as a php.ini directive... UGH!
Other odd stuff:
When Eclipse starts up it fails to open my RSE based project thus displaying edit buffers from the last run as empty
Eclipse will no longer exit! Select File: Exit. Nothing happens. Click on the X in the title bar - nothing happens. Now I have to kill it to close it!
When debugging on the command line you need to tell PHP you want to debug also
http://xdebug.org/docs/remote
says
export XDEBUG_CONFIG="idekey=session_name"
php myscript.php
assuming xdebug is enabled (it doesnt matter which .ini file its in, but there is a standard place per OS for this, usually in a conf.d folder called xdebug.ini which is auto included)
This allows you to debug a cmdline script.
Personally I use Vim with Vdebug extention (xdebug for vim) to debug and nothing other than a command line is needed
What worked for me was using dephpugger. I found the steps to get CLI debugging working here:
https://hackernoon.com/how-debug-php-applications-with-dephpugger-98cc234d917c
I had previously installed xdebug and tried out exussum's answer.
The steps I followed are included here for completeness.
Install dephpugger:
composer global require “tacnoman/dephpugger”:”dev-master”
Put dephpugger on the path:
export PATH=$PATH:$HOME/.composer/vendor/bin
make sure to include in the php file at the breakpoint:
xdebug_break();
open up 2 terminal instances. In one run:
dephpugger debug
In the other run
dephpugger cli /path/file.php
replacing /path/file.php with the path to your file. if you need command line arguments to the php script put the path and arguments in quotes. It still seems a little hacky. I think the real trick is to write in a language that has a better debugger built in.
exussums answer works for me.
In addition I have the following in /etc/php/7.0/cli/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_enable=true
#xdebug.remote_enable=false
And I had to do this: https://github.com/vim-vdebug/vdebug/issues/363
Being able to set break points in a PHP script requires some kind of debugger extension being loaded, either XDebug or Zend Debugger.
And then you need some kind of interface to this debugger to make your wishes about break points known. I am unfamiliar with the Perl debugging, but I haven't heard about any PHP CLI based debugging - it is always taking place in an IDE that is able to handle the debugging protocol of one of the extensions.
Of course there is the good old var_dump();die('hi'); debugging, but this does not include continuing code execution after the script ended. ;)

Find out how PHP is running on server (CGI OR fastCGI OR mod_php)

I use shared hosting.
There is possible to find out whether PHP is running via fastCGI (or maybe CGI) or as Apache module mod_php?
Is it possibly to find out by myself, without asking the hoster?
That's the Server API row on top of phpinfo()'s output:
However, please note that it won't necessarily tell you the exact version of Apache or the exact CGI handler. It just describes the SAPI in use.
You can also call the php_sapi_name() function (or the PHP_SAPI constant, which provides the same info):
Description
string php_sapi_name ( void )
Returns a lowercase string that describes the type of interface (the
Server API, SAPI) that PHP is using. For example, in CLI PHP this
string will be "cli" whereas with Apache it may have several different
values depending on the exact SAPI used
It's still a good idea to check your HSP's documentation because it possible to have several PHP versions available.
Remember you need to run phpinfo() from the same environment you want to check (web server won't tell you about command line and vice-versa):
C:\>php -i | findstr /C:"Server API"
Server API => Command Line Interface
$ php -i | grep 'Server API'
Server API => Command Line Interface
You can use the link below:
How to determine php is running as php cgi or apache module?
or create a file info.php and type
<?php
phpinfo();
?>
now run file with your domain name.
find Server API on file and it show you PHP is running on server with CGI OR Apache
Security consideration: Make sure to delete the file which outputs phpinfo() especially if the website is or is going to be hosted online. The information shown there is a gold mine for hackers.

Categories