public static function exportPNGAsync($slug, $query, $width, $height) { $phantomjs = base_path() . "/node_modules/.bin/phantomjs"; $rasterize = base_path() . "/phantomjs/rasterize.js"; $target = \Request::root() . "/" . $slug . ".export" . "?" . $query; $queryHash = hash('md5', $query); $file = public_path() . "/exports/" . $slug . "-" . $queryHash . ".png"; $tmpfile = $file . "#tmp"; if (!file_exists($file) && !file_exists($tmpfile)) { // Create a temporary marker file so we don't double up on requests touch($tmpfile); $command = $phantomjs . " " . $rasterize . " " . escapeshellarg($target) . " " . escapeshellarg($file) . " '" . $width . "px*" . $height . "px'" . " >/dev/null 2>/dev/null &"; Log::info($command); exec($command); } }