Files
manjapro_v6/load/autoload.js
T
2025-09-21 21:40:17 +07:00

82 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 515 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();