Bonjour,
Je tente désespéramment de créer une tâche automatique quotidienne via le manager, en vain.
Je viens donc requérir votre aide.
J'ai créé un script php qui doit être exécuté tous les jours (à 9h du matin).
Ce script commence bien par #!usr/local/bin/php.ORIG.5_4
Et ensuite voici le code enrichi :
Dans le manager, je spécifie bien l'adresse du script (www/monscript.php), je coche tous les jours et je spécifie l'heure, mais il ne se passe rien.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 <?php setlocale(LC_TIME, "fr_FR"); unlink("./data/updatedb.csv"); unlink("./data/stock.csv"); copy("./data/UPDATEDB.TXT", "./data/updatedb.csv"); $newfichier = fopen("./data/sortie_stock.csv", "w"); // crée le fichier cible s'il n'existe pas ou écrase s'il existe déjà fclose($newfichier); $lines = file('./data/updatedb.csv'); // ouverture du fichier d'origine $fp = fopen("./data/stock.csv","w"); //création du fichier de sortie $tampon = ""; // initialisation de la variable tampon foreach ($lines as $lineNumber => $lineContent) // boucle pour parcourir le fichier d'origine { if (strpos($lineContent,"#<SEPARATOR>#") !== false) // condition si la ligne contient séparateur { $tampon = $tampon . $lineContent; // ajout du contenu de la ligne au tampon $arr_base = explode(";",$tampon); $uc_12 = $arr_base[12]; $ucfirst = ucfirst(mb_strtolower($uc_12)); $tampon = str_replace($uc_12,$ucfirst,$tampon); $uc_13 = $arr_base[13]; $ucfirst = ucfirst(mb_strtolower($uc_13)); $tampon = str_replace($uc_13,$ucfirst,$tampon); $uc_15 = $arr_base[15]; $ucfirst = ucfirst(mb_strtolower($uc_15)); $tampon = str_replace($uc_15,$ucfirst,$tampon); $uc_17 = $arr_base[17]; $ucfirst = ucfirst(mb_strtolower($uc_17)); $tampon = str_replace($uc_17,$ucfirst,$tampon); $uc_18 = $arr_base[18]; $ucfirst = ucfirst(mb_strtolower($uc_18)); $tampon = str_replace($uc_18,$ucfirst,$tampon); $uc_10 = $arr_base[10]; $date = strftime("%d %B %Y", strtotime($uc_10)); $tampon = str_replace($uc_10,$date,$tampon); fputs($fp,$tampon); // écriture de la ligne tampon dans le fichier $tampon = ""; // clear du tampon }else{ // condition si ne contient pas de séparateur $tampon = $tampon . trim($lineContent); // alors ajoute le contenu au tampon déjà existant } } fclose($fp); // fermeture du fichier file_put_contents('./data/sortie_stock.csv', file_get_contents('./data/format.csv') . file_get_contents('./data/stock.csv') ); ?>
De plus, mon site étant sous wordpress, une fois que ce script est exécuté (création d'un fichier à importer dans ma base produit), il faudrait que je planifie l'import via un plugin WordPress intitulé "WP ALL IMPORT".
Voici ce qui est stipulé sur la page qui indique comment faire :
Si quelqu'un a la solution pour me dépatouiller de tout ça.Cron Scheduling
To schedule an import, you must create two cron jobs in your web hosting control panel. One cron job will be used to run the Trigger script, the other to run the Execution script.
Trigger Script URL
Run the trigger script when you want to update your import. Once per 24 hours is recommended.
http://example.com/wp-cron.php?import_k … on=trigger
Execution Script URL
Run the execution script frequently. Once per two minutes is recommended.
http://example.com/wp-cron.php?import_k … processing
Trigger Script
Every time you want to schedule the import, run the trigger script.
To schedule the import to run once every 24 hours, run the trigger script every 24 hours. Most hosts require you to use “wget” to access a URL. Ask your host for details.
Example:
wget -q -O /dev/null "http://example.com/wp-cron.php?import_key=nWjUnRn5&import_id=24&action=trigger"
Execution Script
The Execution script actually executes the import, once it has been triggered with the Trigger script.
It processes in iteration (only importing a few records each time it runs) to optimize server load. It is recommended you run the execution script every 2 minutes.
It also operates this way in case of unexpected crashes by your web host. If it crashes before the import is finished, the next run of the cron job two minutes later will continue it where it left off, ensuring reliability.
Example:
wget -q -O /dev/null "http://example.com/wp-cron.php?import_key=nWjUnRn5&import_id=24&action=processing"
Merci par avance
Partager