Muhtemelen bazı küçük performans bulunanlar, ama bunun ötesinde var?
Dan the docs:
PHP 4.3.3, session_start () çağrılırken itibariyle toplantısı sonrasında daha önce başladı E_NOTICE seviyesinden bir hata neden olur. Ayrıca, ikinci oturum başlatma basitçe göz ardı edilecektir.
Yani hayır, bu "zarar" değil, ancak bir hata atmak olacak. Ve o oluyor ki aslında muhtemelen yanlış bir şey yaptığımızı bir göstergesidir, ve kod ortaya koydu nasıl yeniden düşünmek gerekebilir.
Arayan session_start (); uygulamanızın performansını zarar verebilir.
Aşağıdaki kod bir E_NOTICE tetikleyecek, ama akıllıca bu kadar performans zarar vermez
<?php
session_start();
session_start();
?>
But calling the following will harm the performance! But it's still usefull. If you have a script that takes 3 minutes to run wich is called with XHR (js). In this case it's usefull to use the session_write_close. otherwise the request to the server is blocked until the sessions are released. It could happen that you want to use the sessions at the start of the script and at the end of the script.
<?php
session_start();
session_write_close();
session_start();
?>
But, when you call the session_start(); all information is deserialized, and when you call session_write_closed() it's serialized. So if you have a lot of data it can be really slow!
Aşağıdaki test bu ne kadar etkisi olduğunu gösterir.
Boş oturum ile + yakın 1,0130980014801 sesion_start
Oturum olmadan 1,0028710365295 normal bir döngü
Yakın 12,808688879013 çok başlaması ile birlikte oturumda veri +
1,0081849098206 Normal döngü Agian (yararsız tür)
<?php
//start and clear first session
session_start();
session_destroy();
session_write_close();
//test one
if(true) {
//test loop one
$start = microtime(true);
for($i = 0; $i < 1000; $i++) {
session_start();
usleep(100);
session_write_close();
}
$end = microtime(true);
echo($end - $start);
//test loop 2
echo('<br />');
$start = microtime(true);
for($i = 0; $i < 1000; $i++) {
usleep(100);
}
$end = microtime(true);
echo($end - $start);
}
//fill the array with information so serialization is needed
session_start();
$_SESSION['test'] = array();
for($i = 0; $i < 10000; $i++) {
$_SESSION['test'][$i] = chr($i);
}
session_write_close();
echo('<br />');
//test two
if(true) {
//test loop one
$start = microtime(true);
for($i = 0; $i < 1000; $i++) {
session_start();
usleep(100);
session_write_close();
}
$end = microtime(true);
echo($end - $start);
//test loop 2
echo('<br />');
$start = microtime(true);
for($i = 0; $i < 1000; $i++) {
usleep(100);
}
$end = microtime(true);
echo($end - $start);
}
?>
Zaten oturum açıksa, o zaman bir hata bildirimi dönecek ve yeni bir oturum göz ardı edilecektir. Yani hiçbir zarar yapılır, ama sinir bozucu bir hata var olacaktır.
Bunu yapmak için ihtiyaç buluyorlar Ama eğer ... o zaman kod iyi organize olmayan bir belirtisi olabilir. Muhtemelen bir oturumu başlatmak gibi gereksiz yinelenen görevler kendinizi tutmak nasıl görmek için yararına olacaktır.