gpt4 book ai didi

php - PHP : file operation scope, 参数传输和限制执行访问中的异步操作

转载 作者:可可西里 更新时间:2023-11-01 12:38:41 24 4
gpt4 key购买 nike

我有一个 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);

}

}

我的担忧已在标题中给出,如下所示:

  1. 通过关闭文件操作(如在 called.php 的开头),这会影响所有其他可能正在使用文件操作的脚本,还是仅影响执行此操作时受影响的脚本?
  2. 如果使用 cURL 调用,我会让脚本容易受到不当执行的影响吗?尽管我认为我肯定可以访问 $_SESSION ,如果有人想要执行它,它很容易被欺骗。有什么办法可以解决这个问题?
  3. 考虑到我需要在脚本之间传输的参数很容易达到 ton 字节,因为每个数组大约 400 字节 * x 数组会有什么问题关于执行?

非常感谢您的帮助,我希望您不要认为这是非常广泛的,因为我已经尝试并明确地详细说明了我的所有问题,并且希望在整个过程中得到帮助(比分散它更容易)。请尽可能提供帮助,tyvm。

最佳答案

Q1:文件操作总是影响当前正在执行的脚本,当然包括通过requireinclude加载的所有库。

Q2:根据调用者和被调用者所在的位置,您可以限制访问,例如通过限制对某些 IP 的访问以及可能通过 .htaccess 的访问方法。

喜欢:

<Limit GET POST>
order deny,allow
deny from all
allow from 1.2.3.4
</Limit>

Q3:另外根据两个脚本之间的连接情况,如果你有足够的可用带宽,通常大数据量应该没有问题。

我们有一些运行中的脚本可以定期处理数百兆字节范围内的数据。可能需要通过在 php.ini 中设置 max_execution_time 或使用 ini_set() 来延长或关闭脚本执行时间限制,或者使用 set_time_limit()(这是一种不同的方法)。

关于php - PHP : file operation scope, 参数传输和限制执行访问中的异步操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32562309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com