php.ini ??┃絎?

?祉???激?с??D?????羝<??

?祉???激?с?括???

?????祉???激?с?括?????絵??

DB, memcached 膈???篏帥?c???祉???激?с?括?????茵????翫??????篁ヤ????鴻??絵???????

?掩????????????篏帥?c???祉???激?с?括???

MySQL??篏帥?c???祉???激?с?括???

?祉???激?с?括??????????若??????篏????????????祉???激?с?潟??潟??????絎?臂???????

?? ???若??? sessions

CREATE TABLE `sessions` (
  `id` varchar(32) NOT NULL default '',
  `access` int(10) unsigned default NULL,
  `data` text,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

?? session_mysql.ini

<?php

define("SESSION_DB_HOST", "localhost");
define("SESSION_DB_USER", "test");
define("SESSION_DB_PASS", "test");
define("SESSION_DB_DB", "test");

?>

?? session_mysql.php

<?php

require_once("session_mysql.ini");

// ???若?九?臂????祉???激?с?潟??潟??????篏睡?
ini_set("session.save_handler", "user") or die("ini_set(session.save_handler) failed.");
// ?祉???激?с?潟??潟?????∽?違??荐??
session_set_save_handler('_open', '_close', '_read', '_write', '_destroy', '_clean');
// PHP5.0.5 篁ラ??? session_start() ???若?九?????????????絎?茵?
register_shutdown_function('session_write_close'); 
 
function _open()
{
    global $_sess_db;
 
    $db_host = SESSION_DB_HOST;
    $db_user = SESSION_DB_USER;
    $db_pass = SESSION_DB_PASS;
    $db_db = SESSION_DB_DB;
    
    if ($_sess_db = mysql_connect($db_host, $db_user, $db_pass))
    {
        return mysql_select_db($db_db, $_sess_db);
    }
    
    return FALSE;
}

function _close()
{
    global $_sess_db;
    
    return mysql_close($_sess_db);
}

function _read($id)
{
    global $_sess_db;

    $id = mysql_real_escape_string($id);

    $sql = "SELECT data FROM sessions WHERE id = '$id'";

    if ($result = mysql_query($sql, $_sess_db))
    {
        if (mysql_num_rows($result))
        {
            $record = mysql_fetch_assoc($result);

            return $record['data'];
        }
    }

    return '';
}

function _write($id, $data)
{   
    global $_sess_db;

    $access = time();

    $id = mysql_real_escape_string($id);
    $access = mysql_real_escape_string($access);
    $data = mysql_real_escape_string($data);

    $sql = "REPLACE INTO sessions VALUES ('$id', '$access', '$data')";

    return mysql_query($sql, $_sess_db);
}

function _destroy($id)
{
    global $_sess_db;
    
    $id = mysql_real_escape_string($id);

    $sql = "DELETE FROM sessions WHERE id = '$id'";

    return mysql_query($sql, $_sess_db);
}

function _clean($max)
{
    global $_sess_db;
    
    $old = time() - $max;
    $old = mysql_real_escape_string($old);

    $sql = "DELETE FROM sessions WHERE access < '$old'";

    return mysql_query($sql, $_sess_db);
}

?>

?? test.php

<?php

require_once("session_mysql.php");

  // Initialize a session. This call either creates 
  // a new session or re-establishes an existing one.
  session_start();
 
  // If this is a new session, then the variable
  // $count will not be registered
  if (!session_is_registered("count")) 
  {
    session_register("count");
    session_register("start");
 
    $count = 0;
    $start = time();
  } 
  else 
  {
    $count = $_SESSION['count'];
    $start = $_SESSION['start'];

    $count++;
  }
 
  $sessionId = session_id();
 
  $_SESSION['count'] = $count;
  $_SESSION['start'] = $start;
?>

<!DOCTYPE HTML PUBLIC 
   "-//W3C//DTD HTML 4.0 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd" >
<html>
  <head><title>Sessions</title></head>
  <body>
    <p>This page points at a session 
        (<%= $sessionId %>)
    <br>count = <%= $count %>.
    <br>start = <%= $start %>.
    <p>This session has lasted 
      <?php 
        $duration = time() - $start; 
        echo "$duration"; 
      ?> 
      seconds.

    <p><a href="destroy_session.php">destroy session</a>
  </body>
</html>

TokyoTyrant? ???????祉???激?с?括???

Repcached ???????祉???激?с?括???

memcached ???????祉???激?с?括???

memcached ???泣?若?????<?≪????????若?帥???主????????閟?罕?????箴????????若???????≪???帥?ゃ???????若?帥?с????綽?荀??????????若?帥???????主??????????号????????????荐???с????????????

Memcache?∽?? Memcache?????鴻??篏帥??????????????

sharedance ???????祉???激?с?括???

Mac OS X 筝??с?????ゃ??????????≫??с???障????????с???????c?????????荐若??????????????

?????若?吾?????号???????????馹?

????URL


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS