How to render a file with Blender called from a PHP script?

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

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.

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.

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.

here's my php code ( in this case using system() but all other variants seem to have the same result ):

$swatchId = $args->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"=>$command));
$result = system($command);

this results in the command:

.\blender\blender -b _swatches.blend -o NPRKGAP -F JPEG -x 1 -f 1

which executes correctly in a command window, but not when called in php ( from a web request ).

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.

If anyone can help I'd be eternally grateful.

Answers


Try adding the flags to your blender command.

-noaudio -nojoystick

I am doing something similar, except I'm using python.

Back story: I was getting crazy permission issues when trying to get www-data user to launch blender (what you are also doing). I looked at George Reith's comment and saw in the netrender examples that they make you put noaudio and nojoystick. So I randomly tried it and suddenly www-data can run blender!


Need Your Help

Entity Framework CTP5, code-first. Optional navigation property

asp.net entity-framework code-first

I'm using Entity Framework CTP5 (code-first) and I have two classes:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.