there is one possible status for session_status called PHP_SESSION_DISABLED .
is there any specific function that can disable sessions in php??
Remark: I updated this answer several times by adding more information and striking out previous sentences that I discovered as being erroneous. On the last edit I reformulated it completely, removed the wrong sentences and references to PHP source code.
The documentation of the Sessions extension reads:
Session support is enabled in PHP by default. If you would not like to build your PHP with session support, you should specify the --disable-session option to configure.
Calling session_status() or any other session function on a PHP compiled with --disable-session triggers a PHP Fatal Error that stops the script because the function does not exist:
$ php -m | grep session
$ php -r 'session_start();'
PHP Fatal error: Call to undefined function session_start() in Command line code on line 1
The documentation also says:
The Windows version of PHP has built-in support for this extension. You do not need to load any additional extensions in order to use these functions.
This probably means there is no way to remove the sessions functionality from PHP on Windows.
How to disable the sessions without recompiling PHP
You can disable the session functions by setting empty or invalid values for session.save_handler or session.serialize_handler in php.ini.
For testing you can set session.save_handler, for example, in the command line using the -d option; it overrides the value read from php.ini:
$ php -d session.save_handler=foo -r 'session_start(); var_dump(session_status() == PHP_SESSION_DISABLED);'
PHP Warning: session_start(): Cannot find save handler 'foo' - session startup failed in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. session_start() Command line code:1
bool(true)
As you can see session_start() triggers a warning complaining about the handler not being valid and the session status is disabled (it cannot start).
The sessions cannot be disabled from the PHP code
If you try to set an invalid value to session.save_handler at runtime, ini_set() triggers a warning and doesn't change the value.
$ php -r 'ini_set("session.save_handler", "foo"); session_start(); var_dump(session_status() == PHP_SESSION_ACTIVE);'
PHP Warning: ini_set(): Cannot find save handler 'foo' in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. ini_set() Command line code:1
bool(true)
The session is active. It started successfully.
But they can be re-enabled from the PHP code if they were disabled from settings
However, even if the handler is set as invalid in php.ini or in the command line, the PHP code can fix it before it calls session_start():
$ php -d session.save_handler=foo -r 'ini_set("session.save_handler", "files"); session_start(); var_dump(session_status() == PHP_SESSION_ACTIVE);'
bool(true)
Again, session_start() succeeded, the session is active.
Conclusion
You can disable the session functions by setting empty or invalid value for session.save_handler or session.serialize_handler in php.ini.
Please note that if any of these values is invalid, session_start() triggers a PHP Warning.
However, because both these settings can be modified from everywhere (PHP_INI_ALL means php.ini, httpd.conf, .htaccess, PHP code), they can be, as well, set back to valid values from the PHP code, cancelling this way any effort to disable sessions.
Apparently there is no way to enforce disabling the session, apart from compiling PHP without session support, as explained above.
Upon consulting the PHP source there is the following file at ext/session/tests/session_status_disabled.phpt:
--TEST--
Test session_status() function : disabled
--SKIPIF--
<?php include('skipif.inc'); ?>
--INI--
session.save_handler=non-existent
--FILE--
<?php
echo "*** Testing session_status() : disabled\n";
var_dump(session_status() == PHP_SESSION_DISABLED);
?>
--EXPECTF--
*** Testing session_status() : disabled
bool(true)
So, when there is no save_handler for the session, then session_status() will return PHP_SESSION_DISABLED.
Conclusion:
Disable sessions by doing the following:
Modify this line in the php.ini file:
session.save_handler=non-existent
If you are running a web server it may have its own config file which overrides the ini file. For me, in Apache, I had to comment out the following lines in /etc/httpd/conf.d/php.conf:
#php_value session.save_handler "files"
#php_value session.save_path "/var/lib/php/session"
Or alternatively set the values there instead.
Related
When I try to reset cache from command line with:
php -r "opcache_reset();"
I get the following error message:
Call to undefined function opcache_reset() in Command line code on
line 1
Is there a way to add the opcache_reset function to PHP via php.ini or something like this?
Thanks for help.
You need to check your php.ini config files.
Option 1)
Enable the following flag in your opcache config, likely under mods-available
opcache.enable_cli
Option 2)
If you have different config for CLI and apache2/fpm then check the CLI version has enabled opcache
I need to emails from my PHP script. The Server, which I have hosted my website on, does not allow the use of core PHP mail() function. They say I should write SMTP authentication code for sending emails.
I need to use require_once('System.php'); at the beginning of my PHP script, but the script execution stops beyond this line. In Apache logs of the Server, the log entry says:
AH01071: Got error 'PHP message: PHP Warning: require_once(): open_basedir restriction in effect. File(/opt/plesk/php/5.6/share/pear/System.php) is not within the allowed path(s): (/var/www/vhosts/kbcsurveyors.com/:/tmp/) in /var/www/vhosts/kbcsurveyors.com/preinspection.kbcsurveyors.com/test-smtp-mail.php on line 20\nPHP message: PHP Warning: require_once(/opt/plesk/php/5.6/share/pear/System.php): failed to open stream: Operation not permitted in /var/www/vhosts/kbcsurveyors.com/preinspection.kbcsurveyors.com/test-smtp-mail.php on line 20\nPHP message: PHP Fatal error: require_on................
kbcsurveyors.php is the domain that I have hosted.
For SMTP authentication, I need to use PEAR. I had to include the path/to/pear in the php.ini on the Server. Since, the Server does not allow me to change its own php.ini, I copied it to my domain's folder and appended the path/to/pear to include_path.
Here are commands I used and outputs I had from those commands:
shell_exec('cp /opt/plesk/php/5.6/etc/php.ini /var/www/vhosts/kbcsurveyors.com/httpdocs/includes');
shell_exec('pear config-get php_dir');
OUTPUT: /usr/share/pear
shell_exec('php --ini');
OUTPUT:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/00-ioncube-loader.ini,
/etc/php.d/curl.ini,
....
echo get_include_path();
OUTPUT .:/opt/plesk/php/5.6/share/pear
echo 'Class Exists: '.(class_exists('System', false)) ? 'Yes' : 'No';
OUTPUT: Class Exists: Yes
But again, require_once 'System.php'; throws the above error in Apache log.
The phpinfo()ed a script. It shows the include_path as .:/opt/plesk/php/5.6/share/pear in both Local Value and Master Value.
What mistake am I making? Please help.
Thanks in advance
The problem was solved by appending the path shown by
shell_exec('pear config-get php_dir'); to include_path in php.ini of primary domain and all sub-domains.
I received the following warning, when I tried to access a file from gitub in PHP script:
Warning: DOMDocument::load() [domdocument.load]:
Unable to find the wrapper "https" - did you forget to enable it when you
configured PHP?
in C:\xampp\htdocs\plaoul\text\gittest.php on line 13`
Can you explain what "wrapper" is, what needs to be configured, and generally what's happening?
Uncomment php_openssl.dll extension in the php.ini then restart apache.
In some additions of xampp this line is missing and has to manually inserted!
extension=php_openssl.dll
Wrappers are classes made to access data streams through various protocols, in this case, HTTPS. Read here: http://www.php.net/manual/en/intro.stream.php
You need the HTTP/HTTPS wrapper: http://www.php.net/manual/en/wrappers.http.php, plus PHP built with SSL support.
Does php -m |grep openssl return anything?
I get this error on my production server (CentOS 5.4 and php 5.3.5) :
Warning: include_once(PharData.php): failed to open stream: No such
file or directory in /var/www/ZendFramework/library/Zend/Loader.php on
line 146
Warning: include_once(): Failed opening 'PharData.php' for inclusion
(include_path='/var/www/fw:/var/www/vmms:/var/www/ZendFw/library:.:/usr/share/pear:/usr/share/php')
in /var/www/ZendFw/library/Zend/Loader.php on line 146
Fatal error: Class 'PharData' not found in
/var/www/vm/app/Backup.php on line 40
And this is the code which fail :
$phar = new PharData($imageBackupFile);
$phar->buildFromDirectory($imageDir);
Logger::info("Image directory backed up to: $imageBackupFile");
This code is working fine on my own computer.
PharData should be included by default in php 5.3+ ...
Thanks for your help!
UPDATE :
I am using the Zend Auto loader feature to load the good php files using this code :
require_once("Zend/Loader/Autoloader.php");
$autoloader = Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
Zend autoloader is doing the include_once(PharData.php).
Just because Phar is bundled by default in PHP 5.3 doesn't mean that it's necessarily included in your install. When you build PHP with ./configure, you can pass the --disable-phar to disable the Phar extension.
To confirm this, run the following script:
<?php
phpinfo();
?>
One of the first sections to appear will be the Configure Command section. Review this section to see if the --disable-phar switch is present, and if there is a Phar section to the page in general.
If it's not present, you'll need to contact your host to have it enabled. There's a decent chance, however, that they won't do it for you since it could impact other users depending on how their servers are set up. If this is on your own machine, you'll need to either rebuild PHP without that switch, or install Phar manually from PECL (no idea if this would still work in 5.3, but I don't see why it wouldn't).
I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.