-1

I have a web crawling script I'd like to initiate from a PHP page. It needs to run in the background and be able to be stopped from the page as well. What's the best way of accomplishing this? I know I can run shell line commands from PHP, but it seems like they would not be suitable for something that needs to keep running?

0

1 Answer 1

1

Use PHP's exec() in combination with bash's & like this:

<?php
exec('myscript.py &');

The & causes the process to run in the background.

http://php.net/manual/en/function.exec.php

Possible duplicate:

Asynchronous shell exec in PHP

Sign up to request clarification or add additional context in comments.

2 Comments

Hi i'm trying to use: <?php exec('python3 /var/www/html/test.py > /var/www/html/log/out.txt 2> /var/www$ but it doesn't seem to be working. None of the output is being written to the files and I can't see it with jobs
Just had to chmod my logs directory - quick question, seems like its running but I'm not sure how to stop it?