Skip to content
Advertisement

php exec function taking so much time

i want to run node js in my php code with exec function, but why when i’m running the exec function it’s not showing anything. but when i’m running the node js in terminal as usual it running as normal.

index.js

const wa = require('@adiwajshing/baileys');

 async function connecting() {

const init = new wa.WAConnection();

init.connectOptions.logQR = false;
init.logger.level = 'warn';

init.on('qr', qr => {
    console.log(qr)
})

await init.connect();
await init.getChats();

}
connecting().then(res => console.log(res)).catch(e => console.log(e))

php code

<?php
exec("node index.js", $res, $code);

echo $res;

Advertisement

Answer

This is because exec() is using output buffering, which means all output is only returned after it finished.

You could try to use passthru instead, which will probably return your output immediately.

https://www.php.net/manual/en/function.passthru.php

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement