minify - PHP - Minify::serve - HTTP/1.0 400 Bad Re

2019-08-27 03:11发布

问题:

I worked with minify using this doc:

http://code.google.com/p/minify/wiki/CustomServer

and I have problem that I can't resolve:

<?php

    set_include_path('/srv/home/xyz/public_html/COMPONENTS/_php/minify/min/lib' . 
                PATH_SEPARATOR . get_include_path());
    require 'Minify.php';
    require 'Minify/Cache/File.php';
    Minify::setCache(new Minify_Cache_File()); 

    //no error - everything is ok... until now

    $options = array(
        'files'  => array('/srv/home/xyz/public_html/test1.js', 
                    '/srv/home/xyz/public_html/test2.js', $src),
        'maxAge' => 86400
    );
    Minify::serve('Files', $options);

    //--> HTTP/1.0 400 Bad Request



?>

I tried with:

    'files'  => array('test1.js', 'test2.js', $src),
    'files'  => array('//test1.js', '//test2.js', $src),
    'files'  => array('/srv/home/xyz/public_html/test1.js', 
                      '/srv/home/xyz/public_html/test2.js', $src),

I also put those files in diffrent places without positive result. Question is: what's going on? and why HTTP Request is there?

回答1:

Remove $src variable from an array:

<?php
$options = array(
    'files'  => array('/srv/home/xyz/public_html/test1.js', 
                '/srv/home/xyz/public_html/test2.js'),
    'maxAge' => 86400
);
?>

array('/srv/home/xyz/public_html/test1.js') // this path is absolute physical path
array('//test1.js') // this path is a relative path from document root of the web-server

HTTP Request is there because you should insert a link to your script into html-file:

<script type="text/javascript" src="/js/script.js.php" ></script>

If one of the included file will be not exists, server must send 404-response (NOT FOUND)