Skip to content

Instantly share code, notes, and snippets.

@charliefmoran
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliefmoran/4ba04f363e723cc995b7 to your computer and use it in GitHub Desktop.
Save charliefmoran/4ba04f363e723cc995b7 to your computer and use it in GitHub Desktop.
Run SASS from a PHP script in shared hosting environment
<?php
// run this gist to compile your SASS files in a shared hosting environment (I'm on Dreamhost)
// you must have SASS installed and running fine from the command line already http://sass-lang.com/
// this file will echo your success/failure, and if there's an error create a file detailing what it is
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "./error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open('export GEM_HOME=path/to/your/gems; /path/to/sass scss/style.scss css/style.css', $descriptorspec, $pipes);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
fwrite($pipes[0], 'hello world');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment