Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a new db connection based on an existing one in Zend Framework
    primarykey
    data
    text
    <p>I have a CLI script that uses Zend Framework and forks a child process. It works well when I start it from CLI but when I start it from a bash script the db connection is closed when the bash script ends.</p> <p>I think I need to give the child a new db connection to the same database. Unfortunately the way the connection is originally created is too misterious to me, so I would like to create the new connection based on the existing. How can I do that?</p> <p>This is how its created in the Bootstrap and how I access it later:</p> <pre><code>$resource = $this-&gt;getPluginResource ( 'db' ); $db = $resource-&gt;getDbAdapter (); Zend_Registry::getInstance ()-&gt;dbAdapter = $db; $this-&gt;db = Zend_Registry::get ( 'dbAdapter' ); </code></pre> <p>And this is where I would like to use the new connection:</p> <pre><code>public function start_daemon($worker) { if (file_exists ( $this-&gt;get_pidfile ( $worker ) )) die ( 'process is already running - process pidfile already exists -&gt; ' . $this-&gt;get_pidfile ( $worker ) . "\n" ); $cmd = 'php -f ' . __FILE__ . ' process'; if ($this-&gt;is_win) { $WshShell = new COM ( "WScript.Shell" ); $oExec = $WshShell-&gt;Run ( "$cmd /C dir /S %windir%", 0, false ); exec ( 'TASKLIST /NH /FO "CSV" /FI "imagename eq php.exe" /FI "cputime eq 00:00:00"', $output ); $output = explode ( '","', $output [0] ); $pid = $output [1]; file_put_contents ( $this-&gt;get_pidfile ( $worker ), $pid ); echo ('JobQue daemon started with pidfile:' . $this-&gt;get_pidfile ( $worker ) . "\n"); } else { $PID = pcntl_fork (); if ($PID) { file_put_contents ( $this-&gt;get_pidfile ( $worker ), $PID ); echo ('JobQue daemon started with pidfile:' . $this-&gt;get_pidfile ( $worker ) . "\n"); exit (); // kill parent } //!!Need to create a new db connection here //to make sure the child will have one //when the parent exits posix_setsid (); // become session leader chdir ( "/" ); umask ( 0 ); // clear umask $this-&gt;proc_nice ( 19 ); $this-&gt;process_jobs (); } } </code></pre>
    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.
    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