我正在尝试在 Laravel 控制器中运行以下脚本:
public function importLinkedin(Request $request)
{
$process = new Process("node node/test.js");
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
}
如果我从终端运行以下命令,我会得到预期的输出
node /var/www/website/public/node/test.js
从 Laravel 控制器运行脚本时,浏览器不会停止加载,直到超时。(504网关超时)
test.js 文件看起来像这样
const scrapedin = require('/usr/local/lib/node_modules/scrapedin')
const fs = require('fs')
const cookies = fs.readFileSync('/usr/cookies.json')
const options = {
cookies: JSON.parse(cookies)
}
scrapedin(options)
.then((profileScraper) => profileScraper('https://www.linkedin.com/in/profile-url/'))
.then((profile) => console.log(profile))