Create or add the same content in 2 websites


i installed 2 websites (multisite), and i want to programmatically synchronize some content from the first website to the other. For example, i’m creating a basic page on the first one, i want that the other website create this basic page if he has not it. I did this code :


$bdd2 = new PDO('...');
$bdd3 = new PDO('...');

use DrupalCoreDrupalKernel;
use SymfonyComponentHttpFoundationRequest;
use DrupalnodeEntityNode;

$requete2 = $bdd2->prepare("SELECT nid FROM node"); 
$res2 = $requete2->fetchAll();
$list_ids = array();
foreach($res2 as $row2){
 $list_ids[] = $row2['id'];
$list_ids = ( !empty($list_ids) )? implode( ',', $list_ids) : ''; 

$requete3 = $bdd3->prepare("SELECT * FROM node WHERE nid NOT IN (".$list_ids.") ");  
$res3 = $requete3->fetchAll();
foreach($res3 as $row3){
	$ajouter = "oui"; 
 	$autoloader = require_once 'autoload.php';

					  $kernel = new DrupalKernel('prod', $autoloader);

					  $request = Request::createFromGlobals();
					  $response = $kernel->handle($request);
					$caracteristiques = $bdd3->prepare("SELECT node.type, node__body.langcode, title, body_value, body_format FROM node, node__body, node_field_data WHERE node.nid=node__body.entity_id AND node_field_data.nid=nod.nid");
					$carac = $caracteristiques->fetchAll();

					  $node = Node::create([
					  'type' => $carac['node.type'],
					  'langcode' => $carac['node__body.langcode'],
					  'created' => REQUEST_TIME,
					  'changed' => REQUEST_TIME,
					  'uid' => 1,
					  'title' => $carac['title'],
					  'body' => [
					    'summary' => '',
					    'value' => $carac['body_value'],
					    'format' => $carac['body_format'],

I’m checking the database and the nodes, if the second website has not the node, im creating it with the data from the first website…

Do you have some advices, or better idea ? Thanks.

Drupal version: