当前位置:网站首页>PHP script calls command to get real-time output
PHP script calls command to get real-time output
2022-06-24 21:12:00 【The smell of tobacco】
When writing scripts , It is often necessary to call other commands . While invoking some time-consuming commands , We need to be able to control the script progress in real time .
Generally speaking , The progress of the script is usually obtained through the output of the script .
If it's a bash Script , Then call directly command A You can hand over the power of execution , then command A The output of can be displayed in real time .
If it is perl Script , adopt `` Symbols can also call command A, But the result will be command A You can only get it at the end of the whole , At this point through system command A You can hand over the power of execution to command A, Again , command A The output of can also be displayed in real time .
If it is PHP Script , adopt `` Symbol call , and perl The script is the same , Only in command A Only when it is over can we get back . that PHP How to get the script in real time command A The output of ? You can listen to the process output :
function real_cmd($command){
// Execute the command and open the output pointer of the command
$handle = popen($command, 'r');
while (!feof($handle)) {
// Loop through command output
$data = fgets($handle);
// Refresh output buffer
ob_flush();
flush();
echo $data;
}
// End of command execution , Close the pointer
pclose($handle);
}
边栏推荐
- [普通物理] 光栅衍射
- Reflection - class object function - get method (case)
- Typescript syntax
- Undo log and redo log must be clear this time
- 科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
- C langage pour le déminage (version simplifiée)
- Simulation lottery and probability statistics experiment of the top 16 Champions League
- Dijkstra seeking secondary short circuit (easy to understand)
- What does virtualization mean? What technologies are included? What is the difference with private cloud?
- [performance tuning basics] performance tuning strategy
猜你喜欢

Grating diffraction

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

What does virtualization mean? What technologies are included? What is the difference with private cloud?

伯克利、MIT、劍橋、DeepMind等業內大佬線上講座:邁向安全可靠可控的AI

Learn to use a new technology quickly

Appium introduction and environment installation

After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked

主数据建设的背景

Wechat applet custom tabbar

伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
随机推荐
Leetcode (455) - distribute cookies
Sequence stack version 1.0
Requests requests for web page garbled code resolution
OSI notes sorting
Static routing job supplement
Second understanding permutation and combination
Why do we always "give up halfway"?
全上链哈希游戏dapp系统定制(方案设计)
Common self realization functions in C language development
Smooth live broadcast | analysis of key technologies for live broadcast pain points
Learn together and make progress together. Welcome to exchange
Background operation retry gave up; KeeperErrorCode = ConnectionLoss
JUnit unit test
The difference between RPC and restful
Appium introduction and environment installation
Bean lifecycle flowchart
Record a deletion bash_ Profile file
Leetcode (135) - distribute candy
Mapstacks: data normalization and layered color layer loading
The Google File System (GFS) learning notes