Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Running command through Terminal working fine but using shell_exec not - PHP

I'm writing a PHP script to scrape external website products. The external website uses JavaScript to render product lists that's why my PHP script was not working to scrape those products.

So, I searched for another solution and found JavaScript libraries like PhantomJS and CasperJS.

I've done all my work on my local server but when I'm unable to run my code on Linux.

Here is what I tried through cPanel terminal:

export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs

And

/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js

I got the expected result but when I tried the same in my PHP code using shell_exec, it didn't work. Here is the PHP file code.

shell_exec('export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs');

And

exec('/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js');

NOTE: I also tried adding 2>&1 in the script and I double-checked that the shell_exec command is enabled.

Also, tried using putenv but it didn't work.

putenv("CASPERJS_EXECUTABLE=".SC_PLUGIN_DIR.'includes/casperjs/bin/casperjs');

Let me if you need more detail.

Any help will be appreciated.

Thanks in advance.

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda