PHP exec运行文件 [英] PHP exec to run a file

查看:63
本文介绍了PHP exec运行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近3个小时,我试图告诉PHP运行一个简单的文件.我在本地主机(Windows 8)中将wamp服务器用于Windows.

I am trying for last 3 hours to tell PHP to run a simple file. I am using wamp server for windows in local host (Windows 8)

我已经尝试过与exec()一起使用:

I've tried with exec() working with:

 echo exec('whoami');

我得到了回应,没有权限.

I got response nt authority.

还通过以下方式进行了测试:

Also tested with:

if(function_exists('exec')) {
echo "exec is enabled";
}

那么它可能有用吗?

我正在尝试运行一个名为tester.php的文件

I am trying to run a file called tester.php

当我包含它时,它会起作用,当我需要它时,它会起作用.我需要在后台执行它.当我刷新文件时,代码正常工作而没有任何错误,它将正常写入数据库.

When I include it, its working, when I require it its working. I need to execute it in background. When I refresh file, code is working without any error, it writes to the database normally.

当我尝试执行它时,它不起作用.

When i try to exec it its not working.

我尝试过:

       exec("php http://localhost/diplomski/program/defender/tester.php");
       exec("php-cli http://localhost/diplomski/program/defender/tester.php");
       exec("http://localhost/diplomski/program/defender/tester.php");

不起作用,也尝试过:

        exec("php http://127.0.0.1/diplomski/program/defender/tester.php");
        exec("php-cli http://127.0.0.1/diplomski/program/defender/tester.php");
        exec("php-cli d:\wamp\www\diplomski\program\defender/tester.php")

不工作也尝试过:

        exec("php tester.php");
        exec("php-cli tester.php");
        exec("tester.php");

也尝试过:

         $WshShell = new COM("WScript.Shell");
         $oExec = $WshShell->Run("D:\wamp\bin\php\php5.3.13\php-win.exe -f d:\wamp \www\diplomski\program\defender/tester.php", 0, false);

对此进行了尝试,其无限刷新且不起作用:

Tried this, its refreshing infinitely and not working:

        exec("php d:\wamp\www\diplomski\program\defender/tester.php");
        exec("php-cli d:\wamp\www\diplomski\program\defender/tester.php");
        exec("d:\wamp\www\diplomski\program\defender/tester.php");

我开始在这里拉头发.第一次尝试使用exec()时,我对它或命令不太满意.

I'm starting to pull my hair out here. First time I'm trying to use exec() and I'm not very good with it or with the commands.

推荐答案

给出PHP可执行文件的完整路径和PHP脚本的完整路径.您可以将输出保存在$output中,以查看脚本产生了什么:

Give the full path to the PHP executable and the full path to the PHP script. You can save the output in $output to see what the script produced:

exec("d:/path/to/php.exe d:/wamp/www/diplomski/program/defender/tester.php", $output);
print_r($output);

这篇关于PHP exec运行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆