PHPForever
n00b
- Joined
- Jan 11, 2005
- Messages
- 22
I want to know if there is a way to share data with multiple PHP scripts without using sessions or files?
I'm trying to create a global table (in memory) that any PHP script can modify and lookup. To do that, I obviously need a script that is constantly running. Now I though I can use a singleton class to achieve what I want but to my surprise a singleton class is only "singleton" within the same script/file. That is, if I get a singleton instance (by calling "Server:instance();") in another script, it isn't the instance in the first script - it is a totaly new object. Is that normal?
Here is the singleton class I'm using:
Is there a way to use superglobals to share data with multiple PHP scripts?
I'm trying to create a global table (in memory) that any PHP script can modify and lookup. To do that, I obviously need a script that is constantly running. Now I though I can use a singleton class to achieve what I want but to my surprise a singleton class is only "singleton" within the same script/file. That is, if I get a singleton instance (by calling "Server:instance();") in another script, it isn't the instance in the first script - it is a totaly new object. Is that normal?
Here is the singleton class I'm using:
PHP:
<?php
class Server
{
public static $instance= false;
public static $table= array();
private function __construct()
{
}
public static function instance()
{
if(!Server::$instance)
{
Server::$instance = new Server();
}
return Server::$instance;
}
public static function s_print()
{
print_r(Server::$table);
}
public static function s_add()
{
Server::$table[]= rand(1, 100);
}
}
?>
Is there a way to use superglobals to share data with multiple PHP scripts?