Using Screen and Links2 to run a PHP Web Spider and Detach the Terminal Using Screen and Links2 to run a PHP Web Spider and Detach the Terminal

November 22, 2022

bash debian londinium

I run a PHP based web spider to check the status of websites in londinium.com and was looking for a way to run it in the terminal. In the past I have run it using the refresh html header in a normal browser, but this is a waste as the overhead of sending it to the computer on my desk adds seconds to the process, and as I am indexing thousands of websites it all adds up.

So I came up with the idea of using a terminal browser links2 to load the page and using screen to detach from the ssh terminal window so it can run in the background.

I installed both with the lovely apt command on the debian box thus:

sudo apt install screen links2

and ran it with the '-html-auto-refresh' to allow html refreshes to work.

screen
links2 -html-auto-refresh 1 http://localhost/runProcess 

Screen allows me to run the process in the background and disconnect leaving it running. To leave the process I use the key combination

ctrl a ctrl d

then to return to the window type

screen -r

The advantage is I can log off from the ssh session and reconnect from another computer and return to it. Which also means it can run in the background and you can use the terminal to do other things.


If you would like to contact me with this form on londinium.com, ilminster.net or via Twitter @andylondon