Error while executing proc_open from php script to connect to pgsql

1k Views Asked by At

My PHP script trying to import a .sql file in to postgres DB (Cent OS).

To connect th DB from the PHP script it uses:

$sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
$aDescriptors = array(
    0 => array('pipe', 'r'),
    1 => STDOUT, 
    2 => STDERR
);
$ahPipes = null;
$hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes);
if (!is_resource($hProcess)) fail('unable to start pgsql');

it shows me error: "unable to start pgsql".

And when I am removing @ symbol from the proc_open, it shows me error message....

" proc_open() [<a href='function.proc-open'>function.proc-open</a>]: Descriptor item must be either an array or a File-Handle in <b>/home/nominati/public_html/Nominatim/utils/setup.php"

While $aDescriptors is already an array. Is it any user permission related problem?

Thanks in advance.

1

There are 1 best solutions below

0
On

Try removing stderr:

$aDescriptors = array(
    0 => array('pipe', 'r'),
    1 => STDOUT
//    2 => STDERR
);

I don't know why, but this allowed it to work on my Debian box.