简体   繁体   English

为什么PHP中的session_start抛出警告说文件很大

[英]why session_start in php is throwing warning saying file large

I didn't change any code, all of a sudden when I visited one of the webpages, I see 我没有更改任何代码,当我访问其中一个网页时突然发现

Warning: session_start() [function.session-start]: open(..)Failed: File too large .. index.php on line 2. 警告:session_start()[function.session-start]:open(..)失败:文件太大.. index.php在第二行。

Another error is: 另一个错误是:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent` 警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送

Line1 : <?php 第1行: <?php

Line2 : session_start (); 第2行: session_start ();

Questions : 问题

  1. what is the reason for error that tells File too large? 导致File太大的错误原因是什么? what file is large? 什么文件大?

  2. why all-of a sudden there is an error without any file modification being done? 为什么突然没有任何文件修改就出现错误?

  3. why it is throwing 'headers already sent', when there is nothing defined before session_start , not even a space ? 如果在session_start之前没有定义任何内容,甚至没有空格,为什么它会抛出“已发送标头”?

  4. How to fix this issue? 如何解决这个问题?

1. what is the reason for error that tells File too large? 1.告诉File太大的错误原因是什么? what file is large? 什么文件大?

  • This seems to be the hosting provider issue, as the original file was never modified, and the webpage has been tried from multiple browsers even after clearing the cache. 这似乎是托管服务提供商的问题,因为从未修改过原始文件,并且即使清除了缓存后,也已从多个浏览器尝试了该网页。 When you do session_save_path("../_session1001"); 当您执行session_save_path("../_session1001"); that is mentioned below, you can see that your session is written to that path, so may be that this file was becoming too large in your shared memory,and now that I explicitly mentioned a physical space to write the session files to, this error is no more. 如下所述,您可以看到您的会话已写入该路径,因此可能是该文件在共享内存中变得太大,而现在我明确提到了将会话文件写入其中的物理空间。不再。

4. How to fix this issue? 4.如何解决此问题?

  • Create a directory named say '_session1001' and give chmod 755 so your webserver (app) can write to it. 创建一个名为“ _session1001”的目录,并提供chmod 755,以便您的Web服务器(应用程序)可以写入该目录。
  • Add this line before session_start session_save_path("../_session1001"); 在session_start session_save_path("../_session1001");之前添加此行session_save_path("../_session1001");
  • Ensure you protect the directory via .htaccess file. 确保通过.htaccess文件保护目录。

ie: <?php session_save_path("../_session1001"); session_start(); 即: <?php session_save_path("../_session1001"); session_start(); <?php session_save_path("../_session1001"); session_start();

Read more here : http://php.net/session_save_path 在此处阅读更多信息: http : //php.net/session_save_path

Note: 注意:

Debian does not use the default garbage collector for sessions. Debian不为会话使用默认的垃圾收集器。 Instead, it sets session.gc_probability to zero and it runs a cron job to clean up old session data in the default directory. 而是将session.gc_probability设置为零,并运行cron作业以清除默认目录中的旧会话数据。

As a result, if your site sets a custom location with session_save_path() you also need to set a value for session.gc_probability , 因此,如果您的站点使用session_save_path()设置了自定义位置,则还需要为session.gc_probability设置一个值,

eg: 例如:

<?php session_save_path('/home/example.com/sessions'); ini_set('session.gc_probability', 1); ?>

Otherwise, old files in '/home/example.com/sessions' will never get removed! 否则,'/ home / example.com / sessions'中的旧文件将永远不会被删除!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM