如何在两个PHP脚本之间切换

currently I'm working on a project that fills up a main-database.

Right now it consists of two scripts and a source-database.

What I'm trying to do is:

  1. Script 1 connects to source-db, grabs a city and passes the city as a session-variable via header('Location Script2.php') to Script 2.
  2. Script 2 does a lot of work then (collecting specific data, stores in Array) and saves it in the main-database.

That works fine so far.

  1. Script 2 shall now start Script 1 again, to fetch the next city in the db.

That's where I'm stuck (I tried all solutions I could find on here):

  • again via Header
  • CURL
  • shell_exec
  • etc.

So far, nothing worked.

Any suggestions, ideas or input are very much appreciated!

Many thanks in advance and I look forward to learn from any knowledgeable person on here!

Great evening to you all

Here's the code:

Script 1: Grab the first city with Status "1" (when finished "Status" is updated to "0"):

$con = new mysqli($host, $user, $password, $dbname)
or die ('Could not connect to the database server' . mysqli_connect_error());


// Wählt immer die erste Zeile mit Status "0" aus
$query = "SELECT City FROM citydb WHERE Status = '1' LIMIT 1";

//Packt Stadtname in $location
if ($stmt = $con->prepare($query)) {
    $stmt->execute();
    $stmt->bind_result($field1);
    while ($stmt->fetch()) {
        $loc = $field1;
    }
    $stmt->close();
}

// Überträgt die Variable $location
if ( empty($loc) !== FALSE){
    echo "Nichts mehr da!";
    exit;
    } else {
        $_SESSION['$location'] = $loc;
        header('Location: xxxxxxx/xxxx-get-basicdata.php');
        exit;
    }

Script 2: Processing, saving, restart

$dbkeys = "(" . implode(", ", array_keys($details)) . ")";
$dbvalues = "('" . implode("', '", $details) . "')";
$query = "INSERT INTO data " . $dbkeys . " VALUES " . $dbvalues;

// // UPDATING STATUS IN CITIES-DB
$query = "UPDATE citydb SET STATUS = 0 WHERE City = ('$city')";

if(mysqli_query($conn, $query)){
/////////// THIS IS WHERE I'M STUCK
/////////// here script 1 should be called (at least I thought so)
} else{
echo "ERROR: Not able to execute $sql. " . mysqli_error($conn);
exit;
}

PS: Just for the case the same question came up before or else: I'd be happy if someone could just give me a hint/link. I don't want to have a perfect solution, just an idea what to look into.