From:             sven_oostenbrink at yahoo dot com
Operating system: ALL
PHP version:      5CVS-2004-02-14 (dev)
PHP Bug Type:     Feature/Change Request
Bug description:  Sharing variables, functions and objects between 2 running scripts

Description:
------------
I would really like to see a new feature in PHP that could put a very good
use to the new object possibilities:



Being able to share objects between 2 or more running scripts. Somewhat
equal to the shmop functionalities, but more precise, so that I can
actually make an interface with a number of functions, variables or
objects that can be called by another php script.



Normally, for each page loaded, I would have to create an object from a
class, and destroy it. Next page, I again, have to create an object from
the same class, use it, and destroy it.. Here I have to create and destroy
all the time,  where, in (for example) a C++ program, an object is created
once, and used many. a PHP object is basically create once, use once..



If objects, variables and functions could be shared (passed on) from one
script to another for example, we could do the following example:



I have a database engine object, as a wrapper around the mysql functions.
this object needs to be loaded for each and every php page. This object is
big and heavy, and I loose quite some resources on it for all the creation
db connecting, and destruction of the objects.



With the object sharing, I could start a php page (say, called core.php)
that never dies, it stays in a loop with waits. this page will create one
or more database objects, depending on howmany are needed at each period
of time. 



These objects will immediately connect with the database (with persistent
connecctions if needed). Now, when a page is loaded, and the php of that
page starts running, in stead of creating the SQL object, connecting to
the mysql database, etc, this script only access the interface of
core.php, request a database object, gets the object, and immediately,
this script will be able to access the database without all the fuzz it
normally has to do.. Then, when the script is finished, it will return the
object, mission completed.. The core.php has the object back, and one time
object creating and destructing and database connecting has been saved.



This can be applied to alot of functionalities, and it would save off ALOT
of overhead.. I dont know in how far this is possible, 

Reproduce code:
---------------
more or less pseudo code:



script.php

<?php



  // See if the core interface is available

  while(!$core=check_if_interface_available("core")){

    // Core interface not available. Start the core.php.

    exec("php core.php");

    wait 2 // wait a little to give core.php enough time.

  }



  // core interface is available,

  if(!$sql=$core->get_sql()){

    error("did not receive database object.");

  }



  $sql->use("database_name");

  $sql->query("blah blah");



  // finished, return the database object.

  $core->return_sql($sql));

?>





core.php:

<?php

  $interface_id="core";

  $interfaces=array("stop_core", "get_sql", "return_sql")

  make_interface($interface_id, $interfaces);



  // Make enough database objects.

  $sql_objects=array();

  $sql_objects[]=new sql_object();

  $sql_objects[]=new sql_object();

  $sql_objects[]=new sql_object();



  // Report the sql object that is given away as busy.

  function get_sql(){

    $sql=$sql_objects[free_sql_id];

    $sql->busy();

    return $sql

  }



  // report the sql object that was returned as available.

  function return_sql($sql){

    $sql->available();

  }



  // signal core.php to end.

  function stop_core(){

    $stop_core=TRUE;

  }



  // endless loop...

  while(!$stop_core){

    wait 1;

  }

?>

Expected result:
----------------
core.php will basically run continuously, and act like an SQL object pool
where all requested php pages can ask for a database interface object.





I would think that this would save off alot of time, since objects do not
need to be created for each requested page, and they dont need to be
needlessly destroyed..



This would basically fill up a pretty big hole that I have seen for a long
time in PHP...

Actual result:
--------------
Please let me know what you think of this idea

-- 
Edit bug report at http://bugs.php.net/?id=27251&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27251&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27251&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27251&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27251&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27251&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27251&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27251&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27251&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27251&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27251&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27251&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27251&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27251&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27251&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27251&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27251&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27251&r=float

Reply via email to