note 71612 added to function.pcntl-exec

From: Date: Thu, 07 Dec 2006 18:47:19 +0000
Subject: note 71612 added to function.pcntl-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-120407@lists.php.net to get a copy of this message
Some people might find it useful to run other program using the same process as a different user. This is very usefull if the script is running under root. Here is a simple code to achieve that under *nix PHP CLI: #!/usr/bin/php -q <?php //Enter run-as user below (argument needed to be passed when the script is called), otherwise it will run as the caller user process. $username = $_SERVER['argv'][1]; $user = posix_getpwnam($username); posix_setuid($user['uid']); posix_setgid($user['gid']); pcntl_exec('/path/to/cmd'); ?> I use this as a part of socket program so that a program can be run under different user from remote location. ---- Server IP: 64.71.164.2 Probable Submitter: 67.161.99.243 ---- Manual Page -- http://www.php.net/manual/en/function.pcntl-exec.php Edit -- https://master.php.net/note/edit/71612 Del: integrated -- https://master.php.net/note/delete/71612/integrated Del: useless -- https://master.php.net/note/delete/71612/useless Del: bad code -- https://master.php.net/note/delete/71612/bad+code Del: spam -- https://master.php.net/note/delete/71612/spam Del: non-english -- https://master.php.net/note/delete/71612/non-english Del: in docs -- https://master.php.net/note/delete/71612/in+docs Del: other reasons-- https://master.php.net/note/delete/71612 Reject -- https://master.php.net/note/reject/71612 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120407) next »