phantombuster / nickjs

Web scraping library made by the Phantombuster team. Modern, simple & works on all websites. (Deprecated)
https://nickjs.org
ISC License
500 stars 48 forks source link

Setting environment variables on PHP / Ubuntu #64

Closed yazer79 closed 4 years ago

yazer79 commented 4 years ago

NickJs runs fine on Ubuntu after setting CHROME_PATH manually $ export CHROME_PATH=chromium-browser and running node from terminal

However, I can't run it from PHP unless I execute node script from terminal manually. I want PHP to set the environment variables putenv('CHROME_PATH=/usr/bin/chromium-browser'); This is not working. Any suggestions?

paps commented 4 years ago

Hi there, can you show what method you're using to start NickJS please?

yazer79 commented 4 years ago

Hi paps! $proc = proc_open('node test.js', $in, $out);

paps commented 4 years ago

One of the parameters of proc_open is an array of environment variables to forward to the child process. It should work if you set CHROME_PATH this way.

yazer79 commented 4 years ago

Can't get it to work yet

$in =[];
$out = [];
$env = ["CHROME_PATH"=>"/usr/bin/chromium-browser"];
$cwd = getcwd() ;
$proc = proc_open('node test.js',  $in, $out, $cwd, $env);
yazer79 commented 4 years ago

I don't mind using exec() or shell_exec() if they are more simple to follow putenv(). I hope I can learn more than one way

paps commented 4 years ago

It's hard to tell what's going on. What error are you getting? I need more info to help :)

yazer79 commented 4 years ago

I finally got it! The env vars were loaded right, but the script was failing silently because of the script saving screenshot had no write permissions and I didn't notice that. Thanks a lot :)

paps commented 4 years ago

Nice, glad to hear that :)