CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [Tip/Warning] CCGetSession() & CCSetSession issues when used often

Print topic Send  topic

Author Message
Lucius

Posts: 220
Posted: 11/18/2012, 2:41 PM

Hi,

I have encountered some issues when using the CCGetSession and CCSetSession functions of CCS.

Generally a word of warning and maybe someone would like to do an independent test on different server than that I have available.

Those functions resolve to following code (from Common.php):

function CCGetSession($parameter_name, $default_value = "") {   
session_start();   
$result = isset($_SESSION[$parameter_name]) ? $_SESSION[$parameter_name] : $default_value;   
session_write_close();   
return $result;  
}

function CCSetSession($param_name, $param_value) {   
session_start();   
$_SESSION[$param_name] = $param_value;   
session_write_close();   
}

So like you can see above, nothing really fancy or complicated.

The issue I have encountered when saving and reading a lot of session variables (30-60 function calls). Page lags a lot, which would suggest they are very intensive on resources. When certain amount of such calls (for example 20 CCSetSession's and 40 CCGetSession's) are called in single page execution server shouts 500 Internal Server Error.

To counter this you can group the data in some CSV/array structure and save with single function call. Another solution is to use when possible (because of the scope) the global keyword, which works much faster then sessions.

Anyway, try to use them only when absolutely necessary ! 8-)

I had not expected that those functions would be so very intensive on the server. Maybe someone has more experience and would like to add something to this topic?

EDIT:
Just to add something that I missed above.

Sessions use server side stored files, to keep session data, so some overhead comes from accessing a flat file on server.

The 500 error might come from locking issue. However this is not very likely as the error would be more random as well as the session_write_close(); should prevent this from happening.
View profile  Send private message
bannedone


Posts: 273
Posted: 11/19/2012, 7:10 AM

Hi

Although there is not a limit to how many Session Variables you can have in PHP, it is not advisable to use the amount as described here.

Basically because one of the effects will be very Poor performance as Lucius describes because of the high rate of filesystem access for session files.

If you have alot of visitors to your site the problem can get even bigger.

You also need to realize that the session variable files stay around for the time sepcified by php.ini parameters regarding session lifetime settings. This can cause MANY session variable files to exist that are actually no longer needed.

I have, in some cases, modified these parameters on a site by site basis. When you do this you also need to point to a session save directory only used by that site.

With regards to the 500 error, many things could cause this. Depeding on how your server is configured, the 500 error could even be from reaching the file limit set for your servers directories. Doing this many Session Variable calls could produce millions of session files very quickly as they can also linger for a long time based on when and how PHP does garbage collection based on your session lifertime parameters in php.ini.

It is better to use DEFINES or GLOBALS to store the data you may need.

8-)

PS: If it is neccessary to have that many session variables and calls, PHP can be configured to use your database for the storage of session variables instead of files containing session variables.

_________________
John Real
CodeCharge Studio Support, Training, Consulting, Development, Web based solutions
http://realsites.biz
http://ccselite.com
Other Banned IDs on this Forum. jjrjr1, jjrjr2
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.