session_start is slow to start because my machine uses memcache to cache the session. In this way, I find that mysql query is super slow after the user logs in. Let me introduce a temporary solution.
Below is our test page, just a few sentences
The code is as follows
代码如下 |
复制代码 |
session_start();
echo '111';exit
?>
|
|
Copy code
|
session_start();
echo '111';exit
代码如下 |
复制代码 |
if(!isset($_COOKIE['PHPSESSID']))
{
setcookie('PHPSESSID', time(), time()+60*60, '/' );
header('location:index.php');
exit;
}
|
?>
代码如下 |
复制代码 |
if(!isset($_COOKIE['zenid']) && $_SERVER['HTTP_USER_AGENT']!='UDROBOT')
{
setcookie('zenid', md5(md5(time().rand(999,1000)).rand(999,1000)), time()+60*60, '/' );
header('location:'.$_SERVER['REQUEST_URI']);
exit;
}
.....
?>
|
|
CPU, IO, disk, memory... these are all fine and have been checked. At first, I thought it was a network problem, being blocked, filtering, memory... but in the end it was confirmed that it was not a problem with hardware resources.
Now adding an extra piece of code can solve this problem. It treats the symptoms but not the root cause. We haven’t found out what causes session_start to start slowly.
First automatically create a PHPSESSID, which is automatically assigned without session_start.
The code is as follows
|
Copy code
if(!isset($_COOKIE['PHPSESSID']))
{
setcookie('PHPSESSID', time(), time()+60*60, '/' );
header('location:index.php');
exit;
}
The code is as follows
|
Copy code
|
<🎜>if(!isset($_COOKIE['zenid']) && $_SERVER['HTTP_USER_AGENT']!='UDROBOT')<🎜>
{<🎜>
setcookie('zenid', md5(md5(time().rand(999,1000)).rand(999,1000)), time()+60*60, '/' );<🎜>
header('location:'.$_SERVER['REQUEST_URI']);<🎜>
exit;<🎜>
}<🎜>
<🎜>.....<🎜>
?>
http://www.bkjia.com/PHPjc/629892.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629892.htmlTechArticlesession_start is slow because my machine uses memcache to cache the session, so I find that mysql query is super slow after the user logs in. Okay, let me introduce a temporary solution. ...
|
|
|
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