// const { exec } = require('child_process'); // const path = require('path'); // // Jalur ke executable PHP // const phpExecutablePath = '/www/server/php/74/bin/php'; // Jalur yang sesuai dengan sistem Anda // // Daftar jalur ke file PHP // const phpScriptPaths = [ // path.join(__dirname, 'load_pesan.php'), // path.join(__dirname, 'load_tagihan_flip.php'), // path.join(__dirname, 'create_link_flip.php'), // ]; // // Fungsi untuk menjalankan file PHP // function runPhpScripts() { // phpScriptPaths.forEach((phpScriptPath) => { // console.log(`Running command: ${phpExecutablePath} ${phpScriptPath}`); // exec(`${phpExecutablePath} ${phpScriptPath}`, (error, stdout, stderr) => { // if (error) { // console.error(`Error executing PHP script ${phpScriptPath}: ${error.message}`); // return; // } // if (stderr) { // console.error(`PHP script ${phpScriptPath} stderr: ${stderr}`); // return; // } // console.log(`PHP script ${phpScriptPath} output: ${stdout}`); // }); // }); // } // // Jalankan PHP scripts segera dan kemudian setiap 5 detik // runPhpScripts(); // setInterval(runPhpScripts, 5000); const { exec } = require('child_process'); const path = require('path'); // Jalur ke executable PHP const phpExecutablePath = '/www/server/php/74/bin/php'; // Daftar jalur ke file PHP const phpScriptPaths = [ path.join(__dirname, 'load_pesan.php'), path.join(__dirname, 'load_tagihan_flip.php'), path.join(__dirname, 'create_link_flip.php'), path.join(__dirname, 'load_tagihan_paydisini.php'), ]; // Fungsi untuk menjalankan 1 file PHP (Promise) function runPhpScript(phpScriptPath) { return new Promise((resolve) => { console.log(`Running command: ${phpExecutablePath} ${phpScriptPath}`); exec(`${phpExecutablePath} ${phpScriptPath}`, (error, stdout, stderr) => { if (error) { console.error(`Error executing PHP script ${phpScriptPath}: ${error.message}`); } else if (stderr) { console.error(`PHP script ${phpScriptPath} stderr: ${stderr}`); } else { console.log(`PHP script ${phpScriptPath} output: ${stdout}`); } resolve(); // tetap resolve biar lanjut meskipun error }); }); } // Fungsi utama async function runPhpScripts() { // Jalankan semua script secara paralel await Promise.all(phpScriptPaths.map(runPhpScript)); // Random delay 5–15 detik const nextDelay = Math.floor(Math.random() * (10000 - 5000 + 1)) + 5000; console.log(`Next run in ${nextDelay / 1000} seconds\n`); // Jalankan lagi setelah delay setTimeout(runPhpScripts, nextDelay); } // Jalankan pertama kali runPhpScripts();