Running a process in the background from php

25 Jan 2014 . category: code . Comments

So earlier this week I had a little problem with Apache/PHP killing the task I had running. So after looking around a little online I got some hints and finally came to the conclusion on this line:

echo exec(sprintf("rsh [server] 'nohup %s > %s 2>&1 & echo $! > %s'", 
  "/usr/bin/python2.7 [python script]", 
  "[log file]", 
  "[pid id file]"));

Something to remember, of course this is for Linux


Stuart James  


Stuart James

Assistant Professor in Visual Computing at Durham University. Stuart's research focus is on Visual Reasoning to understand the layout of visual content from Iconography (e.g. Sketches) to 3D Scene understanding and their implications on methods of interaction. He is currently a co-I on the RePAIR EU FET, DCitizens EU Twinning, and BoSS EU Lighthouse. He was a co-I on the MEMEX RIA EU H2020 project coordinated at IIT for increasing social inclusion with Cultural Heritage. Stuart has previously held a Researcher & PostDoc positions at IIT as well as PostDocs at University College London (UCL), and the University of Surrey. Also, at the University of Surrey, Stuart was awarded his PhD on visual information retrieval for sketches. Stuart holds an External Scientist at IIT, Honorary roles UCL and UCL Digital Humanities, and an international collaborator of ITI/LARSyS. He also regularly organises Vision for Art (VISART) workshop and Humanities-orientated tutorials and was Program Chair at British Machine Conference (BMVC) 2021.