PHP Classes

jlaso My Session: Store and get additional session data in files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (9 months ago) RSS 2.0 feedNot enough user ratingsTotal: 140 All time: 9,211 This week: 87Up
Version License PHP version Categories
jlaso-my-session 1.0.10MIT/X Consortium ...5.2PHP 5, Files and Folders, User Manage...
Description 

Author

This class can store and get additional session data in files.

It can set and get values of named keys that are stored in server side files.

The class can serialize in JSON format the list of defined keys before they are stored in a file in a given directory.

It can also read a previously saved file to unserialize and return the values of previously stored keys.

The accesses to keys file is done without locking the file.

Picture of Joseluis Laso
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 56
All time rank: 92219 in Spain Spain
Week rank: 206 Up8 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Example

<?php
   
if (isset($_REQUEST['sid'])) session_id($_REQUEST['sid']);
   
session_start();
   
   
// MySession
   
require '../MySession/MySession.php';
   
$mysession = new MySession(session_id());
   
   
$id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
   
  
   
// this sends to requester the percent of activiy and id,
    // normally the requester is a javascript routine and for not
    // use global id vars now this script returns id
   
print(json_encode(array(
                       
"p" => $mysession->readKey($id),
                       
"id" => $id,
         )));
   
       


Details

This is a complement of session files.

SensioLabsInsight

When you start an activity through ajax request and you want to get info of this activity via ajax, the subsequents requests are blocked waiting for the termination of the first request.

You need to stop using php's session file to serve more ajax request.

Sample of use:

Status.php

<?php

if (isset($_REQUEST['sid'])) session_id($_REQUEST['sid']);
session_start();

// MySession
require '../MySession/MySession.php';
$mysession = new MySession(session_id());

$id = isset($_REQUEST['id'])?$_REQUEST['id']:'';

// this sends to requester the percent of activiy and id,
// normally the requester is a javascript routine and for not
// use global id vars now this script returns id
print(json_encode(array(
                    "p"  => $mysession->readKey($id),
                    "id" => $id,
     )));

    

?>

Activity

This file is that starts the activity and controls the percentage of activity, sample:

<?php

function process_demo(){

// ..code..

$mysession = new MySession( session_id() );

$app->contentType("text/html");

$mysession->writeKey($id, 0);

// relase php session for calls from requester stay attended
session_write_close();

// .. code that process long time ..

// indicates that finishes the long action
$mysession->writeKey($id, "OK");

die();    

}

?>

In index.php bootstrap in SlimFramework project add:

// MySession require './app/others/MySession/MySession.php';


  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file MySession.php Class Class source
Accessible without login Plain text file README.MD Doc. Documentation
Accessible without login Plain text file status.sample.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:140
This week:0
All time:9,211
This week:87Up