Aidez-moi à utiliser "PHP Parallel" dans mon Code suivant
Posté : 12 juin 2022, 04:29
Bonjour.
Je souhaiterais utiliser PHP-8 Parallel (https://github.com/krakjoe/parallel. Ou encore: https://php.net/parallel) dans ma fonction follow_links:
Je cherche donc à traiter tous les URLs stockés dans la variable $starts à la fois de façon parallèle sachant que c'est la fonction get_details qui récupère les données de chaque URL ???
Merci de m'aider.
Je souhaiterais utiliser PHP-8 Parallel (https://github.com/krakjoe/parallel. Ou encore: https://php.net/parallel) dans ma fonction follow_links:
Code : Tout sélectionner
function followLinks($urls) {
global $alreadyCrawled;
global $crawling;
$parser = new DomDocumentParser($page);
foreach($urls as $page) {
$linkList = $parser->getLinks();
foreach($linkList as $link) {
$href = $link->getAttribute("href");
if(strpos($href, "#") !== false) {
continue;
}
else if(substr($href, 0, 11) == "javascript:") {
continue;
}
$href = createLink($href, $url);
if(!in_array($href, $alreadyCrawled)) {
$alreadyCrawled[] = $href;
$crawling[] = $href;
// Output the page title, descriptions, keywords, URL, Image, Video, etc... This output is
// piped off to an external file using the command line.
getDetails($href);
}
}
}
// Remove an item from the array after we have crawled it.
// This prevents infinitely crawling the same page.
array_shift($crawling);
followLinks($crawling);
}
$starts = ["https://website1.dn", "https://website2.dn", "https://website3.dn", "https://website4.dn"];
followLinks($starts);Merci de m'aider.