|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27251 Sharing variables, functions and objects between 2 running scripts
Submitted: 2004-02-14 03:18 UTC Modified: 2013-10-27 17:28 UTC
Avg. Score:4.7 ± 1.0
Reproduced:15 of 17 (88.2%)
Same Version:7 (46.7%)
Same OS:8 (53.3%)
From: sven_oostenbrink at yahoo dot com Assigned: krakjoe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sven_oostenbrink at yahoo dot com
New email:
PHP Version: OS:


 [2004-02-14 03:18 UTC] sven_oostenbrink at yahoo dot com
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:


  // See if the core interface is available
    // 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,
    error("did not receive database object.");

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

  // finished, return the database object.

  $interfaces=array("stop_core", "get_sql", "return_sql")
  make_interface($interface_id, $interfaces);

  // Make enough database objects.
  $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(){
    return $sql

  // report the sql object that was returned as available.
  function return_sql($sql){

  // signal core.php to end.
  function stop_core(){

  // endless loop...
    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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:33 UTC]
-Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: ALL +Operating System: * -PHP Version: 5CVS-2004-02-14 (dev) +PHP Version: *
 [2013-10-27 17:28 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-27 17:28 UTC]
This runs contrary to the model of multi-threading in use by the interpreter, it is simply not possible while PHP is still PHP, and Zend is still Zend.

Paradoxically, there are some extensions that allow you to achieve some of the things you are talking about, gearman, pthreads, but only some; because PHP is still PHP and Zend is still Zend.

Closing the bug, thanks for your input.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jan 20 14:01:23 2021 UTC