您好,欢迎访问一九零五行业门户网

php system()

php函数system详解: 执行外部程序并显示输出资料。 system语法: string system(string command, int [return_var]); system返回值: 字符串 函数种类: 操作系统与环境 system内容说明 本函数就像是 c 语中的函数 system(),用来执行指令,并输出结果。若是 r
php函数system详解:
执行外部程序并显示输出资料。
system语法: string system(string command, int [return_var]);
system返回值: 字符串
函数种类: 操作系统与环境
system内容说明
本函数就像是 c 语中的函数 system(),用来执行指令,并输出结果。若是 return_var 参数存在,则执行 command 之后的状态会填入 return_var 中。同样值得注意的是若需要处理用户输入的资料,而又要防止用户耍花招破解系统,则可以使用 escapeshellcmd()。若 php 以模块式的执行,本函数会在每一行输出后自动更新 web 服务器的输出缓冲暂存区。若需要完整的返回字符串,且不想经过不必要的其它中间的输出界面,可以使用 passthru()。
system()函数的主要功能是在系统权限允许的情况是执行系统命令,windows系统和linux系统都可以执行,windows系统下可执行可执行文件(.exe、.bat等),也可执行cmd命令,linux下用途更广,因为linux系统就是基于命令行的,如基本的ls、cp、rm等。例如在windows系统下有一个bat文件,文件内容为:
@echo off
echo 清空ie临时文件目录…
del /f /s /q “%userprofile%/local settings/temporary internet files/*.*”
del /f /s /q “%userprofile%/local settings/temp/*.*”
echo 正在清除系统临时文件 *.tmp *._tmp *.log *.chk *.old ,请稍等…
del /f /s /q %systemdrive%/*.tmp
del /f /s /q %systemdrive%/*._mp
rem .log大部分有可能有用
rem del /f /s /q %systemdrive%/*.log
del /f /s /q %systemdrive%/*.gid
del /f /s /q %systemdrive%/*.chk
del /f /s /q %systemdrive%/*.old
echo 清空垃圾箱,备份文件和预缓存脚本…
del /f /s /q %systemdrive%/recycled/*.*
del /f /s /q %windir%/*.bak
del /f /s /q %windir%/prefetch/*.*
rd /s /q %windir%/temp & md %windir%/temp
rem cooke和最近历史还是保留吧…
rem del /f /q %userprofile%/cookies s/*.*
rem del /f /q %userprofile%/recent/*.*
echo 清理系统盘无用文件…
%windir%/system32/sfc.exe /purgecache
echo 优化预读信息…
%windir%/system32/defrag.exe %systemdrive% -b
echo 清除系统完成!
echo. & pause
该文件的作用是去除系统垃圾,使用system函数就可以执行它,完成清理工作,代码如下:
其中$callback变量为被执行文件执行后的输出信息。
用linux命令就可以轻松实现tar文件的在线解压工作(必须是linux系统):
如果系统允许,可以使用system函数做更多的工作。
其它类似信息

推荐信息