我有一个PHP脚本,将数据发送到另一个脚本并处理它异步(至少我希望同样得到它).这是代码called.php
include_once("../caller.php");
chdir(__DIR__);
fclose(STDOUT); //THIS
fclose(STDIN); //THIS
fclose(STDERR); //THIS
function giveCake($arg1,$arg2){
global $mysqli;
$sleep = 15; //script has to sleep
(...) code amongst sleep (...)
sleep($sleep);
$_SESSION; //would session variable of the user be available if the script is called as described?
//script caller.php is firstly initiated by a script with pre-defined $_SESSION
//now that I'm thinking maybe it won't since it is called from the command line...
pcntl_exec("/usr/bin/php",Array($_SERVER['argv'][1]));
}
if (!isset($_SERVER["HTTP_HOST"])) { //check if it comes from within the server? localhost?
$arg1 = parse_str($argv[1], $_GET);
$arg2 = parse_str($argv[1], $_POST);
if($arg1 && $arg2){
giveCake($arg1,$arg2);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题在标题中给出,如下:
非常感谢您的帮助,我希望您不要认为这是非常广泛的,因为我已经明确地尝试并详细说明了我的所有问题,并希望在整个过程中提供帮助(比分段更容易).请尽可能帮忙,tyvm.
Q1:文件操作总是会影响当前正在执行的脚本,当然包括通过require
或加载的所有库include
。
Q2:根据调用者和被调用者所处的位置,您可以限制访问,例如限制对某些 IP 的访问,或者通过 .htaccess 访问方法。
喜欢:
<Limit GET POST>
order deny,allow
deny from all
allow from 1.2.3.4
</Limit>
Run Code Online (Sandbox Code Playgroud)
Q3:同样取决于两个脚本之间的连接,如果您有足够的可用带宽,通常数据量大应该没有问题。
我们有一些正在运行的脚本,定期处理数百兆字节范围内的数据。max_execution_time
可能需要通过设置php.ini
或使用ini_set()
, 或 use set_time_limit()
(这是一种不同的方法)来延长或关闭脚本执行时间限制。