Existe-t-il un moyen d'exécuter Google Lighthouse avec php + bash ?
P粉799885311
P粉799885311 2024-03-28 10:21:11
0
1
392

J'ai essayé d'utiliser Google-Lighthouse sur mon site Web. J'ai écrit un fichier php qui appelle un script bash pour exécuter lighthouse-cli.

run_bash.php :

<?php

if(isset($_GET['subject2'])) {

$text = $_GET['subject2'];

$text = escapeshellarg($text);

$command = './rex.sh 2>&1 >> path/mylog ' . $text ;
$output = shell_exec($command);
echo "<pre>$output</pre>";

}
?>

Mon script bash :

rex.sh

#!/bin/bash
SITE=""
SITE=
VALUE=$(echo $SITE | awk -F'//' '{print }')
lighthouse $SITE --output html  --output-path ./path/$VALUE.html

Il existe également un simple formulaire php appelé run_bash.php .

La question est maintenant : Si j'exécute le script bash dans le shell à l'aide de Putty, cela fonctionne bien, mais lorsque j'appelle mon URL et que j'exécute run_bash.php, ces erreurs s'affichent sur le navigateur :

Sun, 05 Jun 2022 19:20:59 GMT LH:ChromeLauncher Waiting for browser...............................................................................................
Sun, 05 Jun 2022 19:21:00 GMT LH:ChromeLauncher Waiting for browser.................................................................................................
Sun, 05 Jun 2022 19:21:00 GMT LH:ChromeLauncher Waiting for browser...................................................................................................
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher Waiting for browser.....................................................................................................
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher Waiting for browser.......................................................................................................

Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:33989
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher:error Logging contents of /tmp/lighthouse.dVx18OP/chrome-err.log

Unable to connect to Chrome

J'aimerais savoir si quelqu'un a déjà fait ça ? Ou est-ce même possible ?

P粉799885311
P粉799885311

répondre à tous(1)
P粉541565322

J'aienfintrouvé la réponse ! J'ai dû utiliser la fonction exec() dans un fichier php pour exécuter un script bash comme indiqué ci-dessous.

$output = exec('./rex.sh  ' . $text  );

Il y a un autre point important. Je ferai tout /var/www/ 路径文件的访问级别更改为 www-data.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!