"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > Proc_Open은 EXEC ()에 비해 PHP에서 스트림 처리를 어떻게 개선 할 수 있습니까?

Proc_Open은 EXEC ()에 비해 PHP에서 스트림 처리를 어떻게 개선 할 수 있습니까?

2025-03-24에 게시되었습니다
검색:258

How Can proc_open Improve Stream Handling in PHP Compared to exec()?

// 스트림 설명자를 초기화합니다. $ descriptorspec = [ 0 =>

, // stdin 1 =>

, // stdout 2 =>

, // stderr ]; // 명령을 실행합니다 $ process = proc_open ( './ test.sh', $ descriptorspec, $ pipes, dirname (__ file__), null); // 출력 스트림에서 읽습니다 $ stdout = stream_get_contents ($ pipes [1]); fclose ($ 파이프 [1]); $ stderr = stream_get_contents ($ pipes [2]); fclose ($ 파이프 [2]); // 결과를 출력합니다 echo "stdout : \ n"; var_dump ($ stdout); echo "stderr : \ n"; var_dump ($ stderr);

// Initialize stream descriptors
$descriptorspec = [
    0 => ["pipe", "r"],  // stdin
    1 => ["pipe", "w"],  // stdout
    2 => ["pipe", "w"],  // stderr
];

// Execute the command
$process = proc_open('./test.sh', $descriptorspec, $pipes, dirname(__FILE__), null);

// Read from the output streams
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);

$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);

// Output the results
echo "stdout:\n";
var_dump($stdout);

echo "stderr:\n";
var_dump($stderr);
최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3