Note that there are some explanatory texts on larger screens.

plurals
  1. POSingle Database Connection in forked PHP Application
    primarykey
    data
    text
    <p>My application uses pcntl_fork to fork a childprocess which monitors a connected router. So I instantiate the class ConnectionManager which forks themself into as many childprocesses as machines are needed to be monitored.</p> <p>I'm using a external DB class which should implement the Singleton pattern but PHP tends to build up a new Database Connection for each forked childprocess. </p> <pre><code>&lt;?php /** * Database * implements Singleton Pattern * Returns one static object via Get() */ include_once '../config/config.php'; class Database{ private $log; public static $dbLink; /** * returns the reference to the only possible mysql resource * @return unknown */ public static function Get(){ if(!self::$dbLink){ $log = Logger::getLogger(__CLASS__); self::$dbLink = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db(DB_SELECT); if(!self::$dbLink){ $log-&gt;fatal("Connect to Database failed"); throw new Exception("Database connection failed: ".mysql_error()); } } return self::$dbLink; } public function Destroy(){ self::$dbLink = null; } } ?&gt; </code></pre> <p>The Problem arises as the number of monitored router increases. Currently we are monitoring around 56 machines, so the application establishes 56 unique mysql_connections to the underlying database. But if the number of machines monitored arises our approach would collide with the mysql_connection_limit.</p> <p>The Database is used to store the traffic of each router. Additionally each childprocess stores runtime-data which contains e.g. the last retrieve of traffic data or the allowance to run.</p> <p>My question is, if its possible to use just one Connection. Something like a cache which collects the SQL statements and sends them as query to the database. </p> <p>But how do I design an approach like mentioned above?</p> <p><em>If further information is needed just ask and i'll post some snippets.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload