This API gives me a headache.. Really can’t figure out what is wrong here..
It just through back this error:
414. That’s an error.
The requested URL /compile... is too large to pr
The file $filename exists when the echo line is unescaped
Code
$Compile = new Net_minify_JS();
$Compile->script = file_get_contents($filename);
//echo $Compile->script;
$Compile->content_length = strlen($Compile->script);
echo '<pre>';
echo $Compile->get();
echo '</pre>';
class Net_minify_JS extends Net_socket {
private $content = null;
public $script = '';
function get(){
$this->url = 'closure-compiler.appspot.com';
$this->path = '/compile?output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code='.urlencode($this->script);
$this->method = 'POST';
$this->connect();
$this->content = $this->get_content();
$string = str_replace("\r\n", "\n", $this->content);
return $string;
}
}
class Net_socket {
public $url = null;
public $path = null;
public $method = 'GET';
public $content_type = 'application/x-www-form-urlencoded';
public $content_length = 0;
public $port = 80;
public $timeout = 20;
private $fp = null;
private $response = null;
function connect(){
$this->response = null;
$this->method = $this->prepare_method();
if($this->fp = fsockopen($this->url, $this->port, $errno, $errstr, $this->timeout)){
$write = "$this->method $this->path HTTP/1.1\r\n";
$write .= "Host: $this->url\r\n";
$write .= "Content-Type: $this->content_type\r\n";
$write .= $this->content_length ? "Content-Length: $this->content_length\r\n":'';
$write .= "Connection: Close\r\n\r\n";
fwrite($this->fp, $write);
while($line = fgets($this->fp)){
if($line !== false) $this->response .= $line;
}
fclose($this->fp);
}
else{
//echo "$errstr ($errno)<br>\n";
}
}
function prepare_method(){
return strtoupper($this->method);
}
function get_content(){
$this->response = str_replace("\r\n", "\n", $this->response);
$expl = explode("\n\n", $this->response);
return $expl[1];
}
}
Sounds like you’re violating the size limits. See https://developers.google.com/closure/compiler/docs/api-ref#errors for how much data is allowed.
And, just for good measure, pass js_code in POST instead of GET.
Edit: You’re using the POST method, but you’re still passing the arguments in the query string instead of the request body. This means they’re all visible in the server’s (and any proxies’) access logs. Even though they’re not secret, the query string is still subject to certain limitations: http://en.wikipedia.org/wiki/Query_string#Compatibility_issues