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.
Related
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.
Has anyone had problems connecting to a sybase database using sybase_connect in PHP running as a nagios plugin?
My script runs perfectly under the same nagios user on the command line but if I run it via nagios it can never connect to the database, sybase_connect always returns a false connector and sybase_get_last_message is empty.
I've checked the environment settings and even though I'm doing, putenv the only thing I can see is the SYBASE variable may not be set
putenv ("SYBPLATFORM=linux");
putenv ("LC_ALL=default");
putenv ("DSQUERY=SYBASE");
putenv ("SYBASE=/usr/local/freetds");
putenv ("LD_LIBRARY_PATH=/usr/local/freetds/lib");
putenv ('PATH=/usr/local/freetds/bin'); // With this on or off makes no difference
$connector = sybase_connect ( "HOST-IN-FREETDS", "USER", "PASSWORD" );
if ($connector === false) {
// Always falls into here if run via nagios, works if run as the same user from the command line
}
I've compared the settings by running:
$return = `set`;
trigger_error ($return, E_USER_NOTICE);
And checked the php error log, I've also pushed phpinfo to a file and done a diff when running it manually and via nagios.
Environment - Ubuntu LTS 14.04, Nagios Core 4.0
Any ideas anyone? Thanks in advance
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.
I have PHP 5.3.3 installed on Centos 6.4 with the memcached.so extension, and httpd is running with version 2.2.15-26. Here is my index.php:
$mc = new \Memcached();
$mc->addServer('127.0.0.1', 11211);
$mc->set("test", "blah");
var_dump($mc->getResultCode());
var_dump($mc->getResultMessage());
var_dump($mc->get("test"));
die;
When I run it from the command line, it works. I get the following:
10:22:33 $ php index.php
int(0)
string(7) "SUCCESS"
string(4) "blah"
The memcache server also works from telnet. However, when I run index.php from the web, it fails. I get the following (from viewing webpage source):
int(47)
string(51) "SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY"
bool(false)
Short of re-installing my OS and trying different versions of crap, can anyone explain what might cause this issue?
Is it an SELinux problem ? Cli can access to Memcached but daemon no. Try this :
getenforce to know if you have SELinux enabled
setenforce 0 to disable it
reboot
Retry your test
If is good, You must configure Apache to access to Memcached.
I have similar issue on CentOS and what I found it I am running SELinux which prevent httpd to connect to memcached. You need to set below,
# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache
httpd_can_network_memcache --> on
Please ensure that your memcache service should bind all IPs. Default value is 127.0.0.1. change it to 0.0.0.0 for supporting all defined Ips. In additional, don't forget to control your iptables or firewall.
I had this problem in WAMP 2.4, running a simple Memcache test script worked from the command line, but not in the browser.
The answer turned out to be stunningly mundane: WAMP had two php.ini files, and I was editing the wrong one.
E.g. Apache used this one: c:\wamp\bin\apache\Apache2.4.4\bin\php.ini
WAMP also had this one: c:\wamp\bin\php\php5.4.12\php.ini
Putting the extension=php_memcache.dll in the correct .ini file fixed things.
My clue something like this was the problem was that phpInfo()'s loaded config file reported different values in the two cases.
I had exactly the same issue as described by the OP. It turned out that the problem was caused by the server list the memcached extension maintains internally. My code was something like:
$serversList = $memcached->getServerList();
if (empty($serversList)) {
$memcached->addServer($host, $port);
}
My initial call to the testing script was done with a wrong value for $port. The call was done from web (apache) not from cli. After i corrected the port and i ran the code again, it was skipping the 'if' and used the existing servers list which was flawed and so it failed again.
Seeing the failure from the web i tested with the cli and it was working perfectly. In the cli the servers list was different from the one in the web. In fact, the server list was empty at each start of the script, even if my script was setting it with each run. Yet it was persisting between calls on the web.
Anyway, after clearing the servers list on the web and setting the correct server, it worked as expected from the web too.
When I look at examples I see it being used without the namespace "\" modifier. Try without it maybe?
http://www.php.net/manual/en/memcache.examples-overview.php
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
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