Search code examples
phplinuxscrapydebiandebian-jessie

How to run scrapy with url parameters from php on linux debian


As the title says... how can i run my scrapy project with specific url paramter from php? I tried this on windows before and it worked perfectly, now on linux it's doing nothing.

On Windows working:

pclose(popen('cd .. & scrapy crawl mySpider -a "urls=http://www.example.com/'.$variable1.'/'.$variable2.'"','r'));

On Linux not working:

pclose(popen('sudo cd .. | sudo scrapy crawl mySpider -a "urls=http://www.example.com/'.$variable1.'/'.$variable2.'"','r'));

I checked already that the php file tries to execute the script as the user www-data so i added this user for testing purpose to sudoer list but it is still not working. When i try to use the command in the shell directly it is working though. I also checked if all files are owned by www-data and are executable and they are. My spider is owned by www-data and has 755 rights. What am i missing here?

Edit: When i change the user to www-data and try to run the command it works, just the php script is not running.


Solution

  • I found a solution. I figured out that php doesn't understand the Pipe operator.

    The correct way to execute that command is the following:

    pclose(popen('cd .. ; scrapy crawl mySpider -a "urls=https://example.com', 'r'));
    

    The semicolon must be used instead.