par
chegmarco » 19 juin 2022, 15:08
Bonjour.
J'essaie d'utiliser la fonction de l'API asynchronous
executeAsync du driver
Cassandra-PHP-Datastax dont la démonstration est sur le lien suivant:
https://github.com/datastax/php-driver/ ... r/features.
Voici donc, ce que j'ai produit comme code:
Code : Tout sélectionner
function insertImage($url, $src, $alt, $title, $description, $keywords, $htmlContentToTxt, $urlClicked, $urlBroken, $lang, $width, $height, $type, $imageExtension, $attr, $providerName, $cmsUsed, $authorName, $authorUrl, $publishedTime, $centroidScore, $graphBasedScore, $scrapeScore, $centroidWeightedScore, $crawledDate) {
global $con;
//création de la column Image
$con->execute("CREATE TABLE IF NOT EXISTS images(siteUrl varchar PRIMARY KEY, imageUrl varchar, alt varchar, title varchar, description varchar,
keywords varchar, textFromWebPage varchar, clicks bigint, broken int, site_lang varchar, width_of_image float,
height_of_image float, image_type varchar, image_extension varchar, image_attribute varchar, providerName varchar,
cmsUsed varchar, authorName varchar, authorUrl varchar, publishedTime timestamp, centroidScore float,
graphBasedScore float, scrapeScore float, centroidWeightedScore float, created_date timestamp) WITH caching='ALL';");
// Using a SSTable Attached Secondary Index (SASI) for "LIKE" (https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/useSASIIndex.html):
$con->execute("CREATE CUSTOM INDEX images_prefix ON images(siteUrl, alt, title, keywords, description, textFromWebPage) USING 'org.apache.cassandra.index.sasi.SASIIndex'");
$query = $con->prepare("INSERT INTO images(siteUrl, imageUrl, alt, title, description, keywords, textFromWebPage, clicks, broken, site_lang, width_of_image, height_of_image, image_type, image_extension, image_attribute, providerName, cmsUsed, authorName, authorUrl, publishedTime, centroidScore, graphBasedScore, scrapeScore, centroidWeightedScore, created_date)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$data = array($url, $src, $alt, $title, $description, $keywords, $htmlContentToTxt, $urlClicked, $urlBroken, $lang, $width, $height,
$type, $imageExtension, $attr, $providerName, $cmsUsed, $authorName, $authorUrl, $publishedTime,
$centroidScore, $graphBasedScore, $scrapeScore, $centroidWeightedScore, $crawledDate
);
$futures = array();
// execute all statements in background
foreach ($data as $arguments) {
// $futures[] = $session->executeAsync($statement, array(
$futures[] = $con->executeAsync($query, array( // "executeAsync" est utilisé dans "CASSANDRA Asynchronous"
'arguments' => $arguments
));
}
// wait for all statements to complete
foreach ($futures as $future) {
// we will not wait for each result for more than 10 seconds. You must ensure that this future has enough time to be executed by calling "Future::get()"
$future->get(10);
}
}
Mes problèmes:
- à propos de la variable
$data. Sur la demo du lien du driver
Cassandra-PHP-Datastax ci-dessus, ils ont utilisé un tableau multidimensionnel mais dans mon cas, c'est juste un tableau simple que je cherche à utilisé.
- Etant donné que c'est mon code ci-dessus est dans une fonction, quelle valeur devrais-je retourner dans le bas de ma fonction
insertImage ???
Dois-je retourner le tableau $futures ou la variable $future->get(10) ???
Merci de me guider s'il vous plaît.
Bonjour.
J'essaie d'utiliser la fonction de l'API asynchronous [B]executeAsync[/B] du driver [B]Cassandra-PHP-Datastax[/B] dont la démonstration est sur le lien suivant: [url]https://github.com/datastax/php-driver/tree/master/features[/url].
Voici donc, ce que j'ai produit comme code:
[CODE]function insertImage($url, $src, $alt, $title, $description, $keywords, $htmlContentToTxt, $urlClicked, $urlBroken, $lang, $width, $height, $type, $imageExtension, $attr, $providerName, $cmsUsed, $authorName, $authorUrl, $publishedTime, $centroidScore, $graphBasedScore, $scrapeScore, $centroidWeightedScore, $crawledDate) {
global $con;
//création de la column Image
$con->execute("CREATE TABLE IF NOT EXISTS images(siteUrl varchar PRIMARY KEY, imageUrl varchar, alt varchar, title varchar, description varchar,
keywords varchar, textFromWebPage varchar, clicks bigint, broken int, site_lang varchar, width_of_image float,
height_of_image float, image_type varchar, image_extension varchar, image_attribute varchar, providerName varchar,
cmsUsed varchar, authorName varchar, authorUrl varchar, publishedTime timestamp, centroidScore float,
graphBasedScore float, scrapeScore float, centroidWeightedScore float, created_date timestamp) WITH caching='ALL';");
// Using a SSTable Attached Secondary Index (SASI) for "LIKE" (https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/useSASIIndex.html):
$con->execute("CREATE CUSTOM INDEX images_prefix ON images(siteUrl, alt, title, keywords, description, textFromWebPage) USING 'org.apache.cassandra.index.sasi.SASIIndex'");
$query = $con->prepare("INSERT INTO images(siteUrl, imageUrl, alt, title, description, keywords, textFromWebPage, clicks, broken, site_lang, width_of_image, height_of_image, image_type, image_extension, image_attribute, providerName, cmsUsed, authorName, authorUrl, publishedTime, centroidScore, graphBasedScore, scrapeScore, centroidWeightedScore, created_date)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$data = array($url, $src, $alt, $title, $description, $keywords, $htmlContentToTxt, $urlClicked, $urlBroken, $lang, $width, $height,
$type, $imageExtension, $attr, $providerName, $cmsUsed, $authorName, $authorUrl, $publishedTime,
$centroidScore, $graphBasedScore, $scrapeScore, $centroidWeightedScore, $crawledDate
);
$futures = array();
// execute all statements in background
foreach ($data as $arguments) {
// $futures[] = $session->executeAsync($statement, array(
$futures[] = $con->executeAsync($query, array( // "executeAsync" est utilisé dans "CASSANDRA Asynchronous"
'arguments' => $arguments
));
}
// wait for all statements to complete
foreach ($futures as $future) {
// we will not wait for each result for more than 10 seconds. You must ensure that this future has enough time to be executed by calling "Future::get()"
$future->get(10);
}
}[/CODE]
Mes problèmes:
- à propos de la variable [B]$data[/B]. Sur la demo du lien du driver [B]Cassandra-PHP-Datastax[/B] ci-dessus, ils ont utilisé un tableau multidimensionnel mais dans mon cas, c'est juste un tableau simple que je cherche à utilisé.
- Etant donné que c'est mon code ci-dessus est dans une fonction, quelle valeur devrais-je retourner dans le bas de ma fonction [B]insertImage[/B] ???
[B]Dois-je retourner le tableau [B]$futures[/B] ou la variable [B]$future->get(10)[/B] ??? [/B]
Merci de me guider s'il vous plaît.