简体   繁体   English

在保持客户端在同一页面上的同时运行第二个PHP脚本

[英]Running a second PHP script while keeping the client on same page

I'm creating a app that requires me to run a second php script while the first script is still running. 我正在创建一个应用程序,要求我在第一个脚本仍在运行时运行第二个php脚本。

I'm new to php programing so I'm sure there's a simple function I can use that I'm just not aware of. 我是php编程的新手,所以我确定有一个我不知道的简单函数可以使用。

Looking forward to any help... 期待任何帮助...

Shane 谢恩

Since you are new to PHP I'm guessing you're looking for the include / require (and include_once / require_once ) language constructs which will execute another PHP script as if it is part of the current script. 由于您是PHP新手,所以我猜您正在寻找include / require (和include_once / require_once )语言结构,它将执行另一个PHP脚本,就像它是当前脚本的一部分一样。

Otherwise if you want it to run as a separate process look into exec , shell_exec , or backticks . 否则,如果希望它作为单独的进程运行,请查看execshell_execbackticks If you need the other PHP script to run as a background process make sure to redirect stdout somewhere (a file or maybe /dev/null if you don't need it) so that your currently executing script doesn't have to wait for it to finish to continue executing. 如果您需要其他PHP脚本作为后台进程运行,请确保将stdout重定向到某个位置(如果不需要的话,可以重定向文件或/ dev / null),以便您当前正在执行的脚本不必等待它完成以继续执行。

This will actually require us to use some Javascript for an ajax call to execute our PHP and return it's data. 实际上,这将要求我们使用一些Javascript进行ajax调用以执行PHP并返回其数据。

I prefer Jquery, which will look similar to this: 我更喜欢Jquery,它看起来类似于:

function callPHP(){           
     $.post('./filetocall.php', {variableid: 'id'}, function (response) {
                        $("#div_for_return_data").val(response);
                });
}

filetocall.php can look like anything. filetocall.php可以看起来像任何东西。 It's output will populate the #div_for_return_data 输出将填充#div_for_return_data

eg: 例如:

<?php echo $_GET['variableid']; ?>

Then just call the Jquery function from anywhere. 然后只需从任何地方调用Jquery函数即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM