Re: [PHP] emalloc / erealloc problem (was: help with custom session handler)

2001-07-01 Thread Delbono



I had the same problem whenever retrieving data from MSSQL using ODBC from a
NULL field.


To solve the problem I had to add a character asd default to that field.

I added a dot.

descr nvarchar  default '.'  .

(the sql sintax here is not the correct one.)




- Original Message -
From: Aral Balkan [EMAIL PROTECTED]
To: Rasmus Lerdorf [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Sunday, July 01, 2001 1:52 AM
Subject: Re: [PHP] emalloc / erealloc problem (was: help with custom session
handler)


 Well finally I am 99.9% sure that the problem is with Metabase. I've
managed
 to bring the code down to the absolute minimum to simplify things and I
can
 now state the bug clearly:

 On Pentium III 500Mhz running WinMe, Apache 1.3.19 and PHP 4.0.5, use of
 Metabase calls in custom session handler to update a MySQL database
randomly
 crash Apache with (again, randomly) errors in either PHP4TS.DLL or
 MSVCRT.DLL.

 When Apache does not crash, the code does work (I tested this with a
simple
 variable increment).

 When the Metabase session handler is replaced with one using MySQL calls,
 the problem goes away.

 Entries noticed in Apache's error.log that may be related are:
 FATAL:  emalloc():  Unable to allocate 1701082243 bytes
 FATAL:  erealloc():  Unable to allocate 369098752 bytes

 I've already written to Manuel about this and I'm sure he'll have the
 problem figured out in no time but in the meanwhile, I'm posting my code
 here so that this post may benefit others trying to do this in the future
 (and with the hope that maybe someone can discover something that *I'm*
 doing wrong that could be causing all this!)

 ?php
 /*
  metabase sesssions library

  error: makes Apache crash randomly with errors in PHP4TS.DLL and
MSVCRT.DLL
  running on WinMe with Apache 1.3.19 and PHP 4.0.5

  based on the code of Sterling Hughes (PHP Developer's Cookbook,
  pgs. 222 - 224) and Ying Zhang (PHPBuilder, Custom Session
  Handlers in PHP4,
 http://www.phpbuilder.com/columns/ying2602.php3?page=1)

  metabase by Manuel Lemos ([EMAIL PROTECTED],
  http://www.phpclasses.upperdesign.com/)

  copyright (c) 2001, aral balkan ([EMAIL PROTECTED])
   http://www.aralbalkan.com
 */

 // metabase database abstraction layer
 require_once metabase/metabase_parser.php;
 require_once metabase/metabase_manager.php;
 require_once metabase/metabase_database.php;
 require_once metabase/metabase_interface.php;

 $SESS_LIFE = get_cfg_var('session.gc_maxlifetime');

 // default life of session to an hour
 if ($SESS_LIFE == '') { $SESS_LIFE = 3600; }

 function on_session_start ($save_path, $session_name)
 {
  global $database;

  /*  db_init.php holds the values for
   $db_type, $db_user, $db_pass, $db_host
  */
  require_once('db_init.php');

  $metabase_init = array(
  Type=$db_type,
  User=$db_user,
  Password=$db_pass,
  Host=$db_host,
  IncludePath=metabase/,
  Persistent=TRUE
  );

  $metabase_error = MetabaseSetupDatabase($metabase_init, $database);

  if ($metabase_error != '') {
   die('Database setup error: '.$metabase_error);
   return false; // failure
  }

  // select database
  $previous_database_name = MetabaseSetDatabase($database, $db_name);
  return true;
 }

 function on_session_end()
 {
  // Nothing needs to be done in this function
  // since we used a persistent connection
  return true;
 }

 function on_session_read ($key)
 {
  global $database;

  $key = MetabaseGetTextFieldValue($database, $key);

  $stmt = SELECT sessionData FROM sessions;
  $stmt .=  WHERE sessionID = $key;
  $stmt .=  AND sessionExpire  . time();

  if (!($result = MetabaseQuery($database, $stmt))) {
// query failed
echo ' Main query (sql) failed.'.$e;
echo ' Error: '.MetabaseError($database).$e;
die();
  }

  $stmt_rows = MetabaseNumberOfRows($database, $result);

  if ($stmt_rows) {
   $sessionData = MetabaseFetchResult($database, $result, 0,
'sessionData');;
   return($sessionData);
  } else {
   return false;
  }
 }

 function on_session_write ($key, $val)
 {
  global $session_db, $SESS_LIFE;
  global $database;

  // convert the text value to a format suitable for use in current
database
  $expiry = time() + $SESS_LIFE;
  $key = MetabaseGetTextFieldValue($database, $key);
  $val = MetabaseGetTextFieldValue($database, $val);

  $replace_stmt = REPLACE INTO sessions (sessionID, sessionData,
 sessionExpire)
  . values($key, $val, $expiry);

  $success = MetabaseQuery($database, $replace_stmt);

  return $success;
 }

 function on_session_destroy ($key)
 {
  global $database;

  $key = MetabaseGetTextFieldValue($database, $key);
  $stmt = DELETE FROM sessions WHERE sessionID = $key;
  $success = MetabaseQuery($database, $stmt);
  return $success;
 }

 function on_session_gc ($max_lifetime)
 {
  global $database;

  $stmt = delete from sessions where sessionExpire   . time();
  $success = MetabaseQuery($database, $stmt);
  return $success;
 }

 // Set the save handlers
 session_set_save_handler

[PHP] emalloc / erealloc problem (was: help with custom session handler)

2001-06-30 Thread Aral Balkan

ok, I found what's making Apache crash... my getting entries like:

FATAL:  emalloc():  Unable to allocate 1701082243 bytes
FATAL:  erealloc():  Unable to allocate 369098752 bytes

in the log. Somehow when I query the database it must be trying to
allocate -- unless my eyes deceive me -- ~1.6 GBs of memory in the first
entry and ~350 Megs in the second.

What could be causing this???

As I mentioned earlier, I have a custom session handler set up that uses
Manuel Lemos' Metabase library to save the session to a database (of the
supported ones, I'm using mySQL.)

I hope this message makes it to the list in a day or so (I really don't
understand why the list is so slow...) because this is driving me crazy!

Aral :)
__
([EMAIL PROTECTED])
New Media Producer, Kismia, Inc.
([EMAIL PROTECTED])
Adj. Prof., American University
¯¯



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] emalloc / erealloc problem (was: help with custom session handler)

2001-06-30 Thread Aral Balkan

Rasmus,

When I try it with the MySQL handler you provided everything goes well -- no
errors. I guess I was hoping that the problem was with some php.ini setting
or something and not with Metabase as I'm dreading going into all code but
alas, I guess I must.

Do you have any idea what sort of database query could cause a memory leak
like that? Could it have anything to do with the serialized data being
written to the database having a '|' character and that character somehow
being interpretted as a concatenation character in a Metabase function?

I'm going to look into this and let you know if I find a solution (I really
hope I do as my thesis pretty much depends on it!)

Thanks again for all your help,

Aral :)

__
([EMAIL PROTECTED])
New Media Producer, Kismia, Inc.
([EMAIL PROTECTED])
Adj. Prof., American University
¯¯



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] emalloc / erealloc problem (was: help with custom session handler)

2001-06-30 Thread Aral Balkan

Well finally I am 99.9% sure that the problem is with Metabase. I've managed
to bring the code down to the absolute minimum to simplify things and I can
now state the bug clearly:

On Pentium III 500Mhz running WinMe, Apache 1.3.19 and PHP 4.0.5, use of
Metabase calls in custom session handler to update a MySQL database randomly
crash Apache with (again, randomly) errors in either PHP4TS.DLL or
MSVCRT.DLL.

When Apache does not crash, the code does work (I tested this with a simple
variable increment).

When the Metabase session handler is replaced with one using MySQL calls,
the problem goes away.

Entries noticed in Apache's error.log that may be related are:
FATAL:  emalloc():  Unable to allocate 1701082243 bytes
FATAL:  erealloc():  Unable to allocate 369098752 bytes

I've already written to Manuel about this and I'm sure he'll have the
problem figured out in no time but in the meanwhile, I'm posting my code
here so that this post may benefit others trying to do this in the future
(and with the hope that maybe someone can discover something that *I'm*
doing wrong that could be causing all this!)

?php
/*
 metabase sesssions library

 error: makes Apache crash randomly with errors in PHP4TS.DLL and MSVCRT.DLL
 running on WinMe with Apache 1.3.19 and PHP 4.0.5

 based on the code of Sterling Hughes (PHP Developer's Cookbook,
 pgs. 222 - 224) and Ying Zhang (PHPBuilder, Custom Session
 Handlers in PHP4,
http://www.phpbuilder.com/columns/ying2602.php3?page=1)

 metabase by Manuel Lemos ([EMAIL PROTECTED],
 http://www.phpclasses.upperdesign.com/)

 copyright (c) 2001, aral balkan ([EMAIL PROTECTED])
  http://www.aralbalkan.com
*/

// metabase database abstraction layer
require_once metabase/metabase_parser.php;
require_once metabase/metabase_manager.php;
require_once metabase/metabase_database.php;
require_once metabase/metabase_interface.php;

$SESS_LIFE = get_cfg_var('session.gc_maxlifetime');

// default life of session to an hour
if ($SESS_LIFE == '') { $SESS_LIFE = 3600; }

function on_session_start ($save_path, $session_name)
{
 global $database;

 /*  db_init.php holds the values for
  $db_type, $db_user, $db_pass, $db_host
 */
 require_once('db_init.php');

 $metabase_init = array(
 Type=$db_type,
 User=$db_user,
 Password=$db_pass,
 Host=$db_host,
 IncludePath=metabase/,
 Persistent=TRUE
 );

 $metabase_error = MetabaseSetupDatabase($metabase_init, $database);

 if ($metabase_error != '') {
  die('Database setup error: '.$metabase_error);
  return false; // failure
 }

 // select database
 $previous_database_name = MetabaseSetDatabase($database, $db_name);
 return true;
}

function on_session_end()
{
 // Nothing needs to be done in this function
 // since we used a persistent connection
 return true;
}

function on_session_read ($key)
{
 global $database;

 $key = MetabaseGetTextFieldValue($database, $key);

 $stmt = SELECT sessionData FROM sessions;
 $stmt .=  WHERE sessionID = $key;
 $stmt .=  AND sessionExpire  . time();

 if (!($result = MetabaseQuery($database, $stmt))) {
   // query failed
   echo ' Main query (sql) failed.'.$e;
   echo ' Error: '.MetabaseError($database).$e;
   die();
 }

 $stmt_rows = MetabaseNumberOfRows($database, $result);

 if ($stmt_rows) {
  $sessionData = MetabaseFetchResult($database, $result, 0, 'sessionData');;
  return($sessionData);
 } else {
  return false;
 }
}

function on_session_write ($key, $val)
{
 global $session_db, $SESS_LIFE;
 global $database;

 // convert the text value to a format suitable for use in current database
 $expiry = time() + $SESS_LIFE;
 $key = MetabaseGetTextFieldValue($database, $key);
 $val = MetabaseGetTextFieldValue($database, $val);

 $replace_stmt = REPLACE INTO sessions (sessionID, sessionData,
sessionExpire)
 . values($key, $val, $expiry);

 $success = MetabaseQuery($database, $replace_stmt);

 return $success;
}

function on_session_destroy ($key)
{
 global $database;

 $key = MetabaseGetTextFieldValue($database, $key);
 $stmt = DELETE FROM sessions WHERE sessionID = $key;
 $success = MetabaseQuery($database, $stmt);
 return $success;
}

function on_session_gc ($max_lifetime)
{
 global $database;

 $stmt = delete from sessions where sessionExpire   . time();
 $success = MetabaseQuery($database, $stmt);
 return $success;
}

// Set the save handlers
session_set_save_handler(on_session_start, on_session_end,
   on_session_read, on_session_write,
   on_session_destroy, on_session_gc);

?

Thanks,
Aral :)

__
([EMAIL PROTECTED])
New Media Producer, Kismia, Inc.
([EMAIL PROTECTED])
Adj. Prof., American University
¯¯



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]