search
Homephp教程php手册PHP session_start()很慢问题分析与解决办法

PHP session_start()很慢问题分析与解决办法

Jun 13, 2016 am 09:46 AM
phpsessionstartone timeandintroduceaboutanalyzeMethodclassmatearticlesolvequestion

本文章来给各位同学介绍一下关于PHP session_start()很慢问题分析与解决办法,希望碰到此问题的同学可进入参考。


最近在做东西的时候发现一个问题

有一个接口挂了 ,然后进行测试访问地址的时候,浏览器就一直处于等待响应的状态

怎么访问都不行,只有重启web服务器才行。

如果不重启web服务器进行代码调试,总发现在session_start()的时候就不能进行下去了

问题原因后来终于明白了:

因为浏览器发送的请求还是在web服务器中建立了线程进行了请求的处理,由于session是在服务器端存储

而浏览器处于等待响应的状态就是表明了web服务器正在处理你的请求,但是由于响应超时时间很长,你也许进行了下一次的调试。

在上一个请求还未死亡之前,它一直占用着你的session资源,而session资源是不能共享的,你再次请求的就一直会在等待session资源的获取。

也就是说只有等你上一个请求结束的时候你才能正常获取session资源并且进入代码的解析


以前发现PHP页面调用session_start()方法时很慢,甚至会用上几十秒钟,现在终于发现原因。

解决办法


因为session使用文件,多个请求时会锁住Session文件,尽量在不用Session时尽早释放Session.
使用 session_write_close() 方法

例如

 代码如下 复制代码

session_start(); //starts the session
$_SESSION['user']="Me";
session_write_close();   // close write capability
echo $_SESSION['user']; // you can still access it

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools