title: How to render a file with Blender called from a PHP script?
body: <p>I'm writing a basic web service to render colour swatches with nice lighting and shadows, using blender in its 'command line' mode, and called from a php script ( that also handles cataloging swatches in a database ). Everything is running under apache on win32, with php 5.2</p>
  
  <p>Everything seems to be working well until the final step of actually rendering something at which point all fails. I've tried using all the different php execution commands ( exec(), system(), passthru() etc. ) and all have the same result - eg nothing at all. The weird thing is that it IS working because if I pass in a malformed argument to blender, then php echoes the correct error message from blender, which verifies that it is definitely starting the program. If I supply correct arguments then exec() etc. just hang, and no blender process appears in the task manager.</p>
  
  <p>I have a feeling its a file permissions problem as Blender needs to write a jpg file to the web folder ( which is sitting in the default apache install dir, eg: within program files ), but I have no idea how to set the correct permissions under windows.</p>
  
  <p>executing my render command from a command window does exactly what it should and outputs the rendered file, but the same command in PHP fails.</p>
  
  <p>here's my php code ( in this case using system() but all other variants seem to have the same result ):</p>
  
  <pre><code>$swatchId = $args-&gt;swatchId;
  $sql = "SELECT * FROM `colours` WHERE `Id` = ".$swatchId." LIMIT 0, 1 ";
  $rows = mysql_query($sql);
  $command =  ".\blender\blender -b _swatches.blend ";
  
  while ($row = mysql_fetch_assoc($rows)) {
      $filename = $row["ProductCode"];
      $red = $row["Red"];
      $green = $row["Green"];
      $blue = $row["Blue"];
  }
  
  $command = $command."-o ".$filename." -F JPEG -x 1 -f 1";
  echo json_encode(array("Command"=&gt;$command));
  $result = system($command);
  </code></pre>
  
  <p>this results in the command:</p>
  
  <pre><code>.\blender\blender -b _swatches.blend -o NPRKGAP -F JPEG -x 1 -f 1
  </code></pre>
  
  <p>which executes correctly in a command window, but not when called in php ( from a web request ).</p>
  
  <p>I have safe mode turned off in PHP, and have bumped up the maximum memory a script can use, though the blend being rendered is not that demanding.</p>
  
  <p>If anyone can help I'd be eternally grateful.</p>