PHP uses a permission denied notice solution encountered by the session, Permissionnotice
If you are using apt-installed PHP under Ubuntu/debian, you may have a small chance of encountering this hint when you use the session.
Copy the Code code as follows:
PHP Notice:session_start (): Ps_files_cleanup_dir:
Opendir (/VAR/LIB/PHP5) Failed:permission denied (13)
in/home/laruence/www/htdocs/index.php on line 22
This is because, in PHP, if File_handler is used as the session's save handler, then there is a probability that the GC process of the session will run every time session_start.
Copy CodeThe code is as follows:
Have omitted
int nrdels =-1;
Nrand = (int) ((float) PS (gc_divisor) * PHP_COMBINED_LCG (Tsrmls_c));
if (Nrand < PS (gc_probability)) {
PS (MoD)->s_gc (&ps (Mod_data), PS (gc_maxlifetime), &nrdels tsrmls_cc);
}
Have omitted
The reason for this warning is that in apt PHP, the default directory for session/VAR/LIB/PHP5 is 733 with sticky bit, which is
Copy CodeThe code is as follows: DRWX-WX-WT root root
In general, PHP workers are running in a non-root identity, so there is no permission to open this folder (but because can write, so does not affect the normal session file read). The following code in the S_GC, then, triggers the notice at the beginning:
Copy CodeThe code is as follows:
For file handler, S_GC indirectly calls Ps_files_cleanup_dir:
dir = Opendir (dirname);
if (!dir) {
Php_error_docref (NULL tsrmls_cc, E_notice,
"Ps_files_cleanup_dir:opendir (%s) failed:%s (%d)",
DirName, Strerror (errno), errno);
return (0);
}
Of course, under the Ubuntu/debian, there are GC recycling, but the external cron process to complete, the default in/ETC/CRON.D/PHP5:,
Copy CodeThe code is as follows:
09,39 * * * * root [-x/usr/lib/php5/maxlifetime]
&& [-D/VAR/LIB/PHP5] && find/var/lib/php5/
-type f-cmin +$ (/usr/lib/php5/maxlifetime)-print0
| Xargs-n 200-r-0 RM
In addition, you can see that there are two key variables when judging whether S_GC is running: PS (gc_divisor) and PS (gc_probability), which correspond to two configuration items with the same name for the runtime configuration item of the session, respectively:
Session.gc_probability and Session.gc_divisor, they default to 1 and 100 respectively.
The PHP_COMBINED_LCG is a random number generator that generates random numbers ranging from 0 to 1, so the above discriminant is equivalent to:
Copy the Code code as follows:
Rand < Probability/gc_divisor
That is, by default, it is almost 100 times that a GC process can be called. So that's the small probability that you can see this notice.
To close this notice, just set:
session.gc_probability = 0, so that S_GC is not running at all possible.
Of course, you can also change the permissions of this folder ...
PHP Session Permission Issue
Session save path C:\WINDOWS\TEMP\ does not develop write permissions to Web users
It means that you have no authority. Can't use Session_Start create session
Why did the server Report session_start () Permission denied (13) error?
This error appears to be due to the fact that the directory hosting the session file does not have open write access to Apache users. To solve this problem, simply set the Session.save_path in the PHP config file php.ini to the temp directory, example: Session.save_path = "/TMP/PHP5" Save php.ini and then restart Apache to take effect. To build the Technical Learning Forum website to view the answer details >>
http://www.bkjia.com/PHPjc/854358.html www.bkjia.com true http://www.bkjia.com/PHPjc/854358.html techarticle PHP using the session encountered a permission denied notice solution, permissionnotice if in Ubuntu/debian, using apt installed PHP, then when using the session, It could be ...