#isU', $feedContent, $titles, PREG_SET_ORDER); preg_match_all('#(.*)#isU', $feedContent, $links, PREG_SET_ORDER); $commands = []; foreach ($titles as $key => $title) { $link = $links[$key] ?? null; if (!$link) { continue; } $title = $title[1]; $link = $link[1]; $hash = md5($title.$link); if (!isset($cache[$hash])) { $cache[$hash] = true; $json = json_encode([ 'text' => sprintf($template, $title, $link), ]); $commands[] = sprintf( 'curl -i -X POST -H "Content-Type: application/json" -d %s %s', escapeshellarg($json), escapeshellarg($hookUrl) ); } } file_put_contents($cacheFile, json_encode($cache)); foreach ($commands as $command) { shell_exec($command); }