包括两次php文件?

I am working on a page that demands that a certain php code is included at runtime - however, at some point in the code below, the variable in that included file is to be rewritten by a remote curl POST request, so I need to re-include the file to read the new value of the variable.

Can I "include" it again to reload the new value? Or is a double include of the same file within the same code not allowed?

EDIT:

Here's what I'm doing exactly:

  1. include a file, that contains 1 variable

  2. run a check in an online API to make sure the URL from the variable is not in the database

  3. if it is, initiate a cURL POST request to a page on my second domain, that starts a chain of events there

  4. after that chain is completed, the second page sends a cURL request to another page on my first domain - the request contains another URL which it passes to a page on my first domain, which in turns grabs that and overwrites the initially included file with the new value for the variable

  5. back to my initial code - I now have a new value for that previously included variable, so I need to "reload" it somehow, because I will be using it a bit later in the code of the same page; won't re-including the file be best?

I think you should move the "later part" of the code in your first PHP file to the file that overwrites your initial variable in #4. Else, move that code to new php file altogether.

You can also implement a web-hook kind of system where you'd pass the "variable" to the first code as a GET/POST parameter. So, the first time that code gets called it will check for the variable. If empty, then it does what you mentioned in steps 1-4.

Then step #4 calls that PHP code again, but passing a variable value. Hence, instead of executing the first part of the code, the file executes the later part.

In any event, your code seems to be too convulated, and is best to split it into functions and classes or something.

I ended up using the following:

$newly_updated_file = "file_with_variable.php";
$lines = file($newly_updated_file);
$new_variable = $lines[15];

Ought to do fine.