开发者

empty output when calling pg_dump under php code

开发者 https://www.devze.com 2023-03-09 00:47 出处:网络
I need to make a dump via pg_dump in php so i\'ve got a function like this: function fnDump() { exec(\"/usr/local/bin/sudo -u pg_user /usr/local/bin/pg_dump mon_al开发者_如何学JAVAarm > /usr/home/

I need to make a dump via pg_dump in php so i've got a function like this:

function fnDump()
{
    exec("/usr/local/bin/sudo -u pg_user /usr/local/bin/pg_dump mon_al开发者_如何学JAVAarm > /usr/home/user/monitor_test/renew_db/mon_alarm.sql",$out);
    var_dump($out);
}

The problem is that mon_alarm.sql file is empty. But when i execute this command via command line everything works fine. What should i change to create a dump in php?


If you're running PHP under a standard webserver setup, that won't work because it will run under the context of the webserver user, so sudo won't let you change user context like that.

If this is a script you're going to have to adjust sudo to run only the pg_dump command as passwordless sudo permissions for the user, otherwise your sudo command will prompt for a password and ruin your automated process.

0

精彩评论

暂无评论...
验证码 换一张
取 消