PHP async without system calls -



PHP async without system calls -

due attack on our server lastly year, have blocked scheme calls via php:

## php.ini disable_functions = exec, passthru, shell_exec, system, proc_open, popen, curl_exec, curl_multi_exec, parse_ini_file, show_source, eval

but has stopped async function working used send email in background.

is there purely php 'safe' way create async phone call without opening exec() function 1 time again ?

function doemail($subject,$body,$to){ $pwd = realpath(dirname(__file__)); $body = urlencode($body); $subject = urlencode($subject); $mailpage = $pwd."/email.php"; $command = "$mailpage $subject $body $to"; bgexecute($command); } ## asyncronous php - multi-tasking (email etc) function bgexecute($command) { if (substr(php_uname(), 0, 7) == "windows") pclose(popen("start /b ". $command, "r")); // windows $exec = "/usr/bin/php -f $command > /dev/null &"; // ubuntu exec($exec); }

well, if want maintain sending arbitrary commands without allowing sending arbitrary commands, no.

if asking if there way execute external applications on demand php, yes.

one way write commands file , have process monitors file change.

$filename = '/tmp/myfile.txt'; $prevmtime = 0; while (true) { clearstatcache(); //do in 2 steps in case have php < 5.4 $mtime = stat($filename); $mtime = $mtime['mtime']; if ($mtime > $prevmtime) { $prevmtime = $mtime; print("file ${filename} changed\n"); } usleep(10); }

another utilize sockets accomplish same thing.

the thing neither of solutions silver bullet: if allow arbitrary commands executed, gain little no security.

you need define how much security want. need decide how much flexibility want.

one way done having process (socket or file based) configure execute list of executables , have php send commands it.

php

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -