• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

php cross script data questions

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:

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?
 
I will hesitate to say that there are no other ways to share info between scripts, but sessions and files/databases are the preferred and intended methods.
 
Back
Top