Welcome! » Log In » Create A New Profile

HTMLPurifier is too BIG ?

Posted by Yujin 
Yujin
HTMLPurifier is too BIG ?
December 01, 2007 03:54PM

Hi,

Do i need to use all the code in "library" folder with my script ?

HTMLPurifier itself take 1 MB of space. Do i have to use all the files or a minimal set of files that can be used for basic functionality ?

Thanks,

Yujin

Re: HTMLPurifier is too BIG ?
December 01, 2007 07:45PM

The library/ directory are the minimal files you need to run HTML Purifier. You may be interested in downloading the standalone version, which places most of the source code in a single, manageable source file (there still are a few more miscellaneous files outside, but the number is greatly reduced).

HTML Purifier is a big library, unfortunately. :-)

Quickquestion
Re: HTMLPurifier is too BIG ?
September 07, 2008 12:47PM

For performance is the standard version better? I'm guessing it only loads the functions that you need or something? With the standalone, does that entire like ~500kb standalone.php file always get loaded?

Thanks

Re: HTMLPurifier is too BIG ?
September 07, 2008 01:49PM

HTML Purifier basically needs everything in the package, so autoloading doesn't give you any appreciable performance benefit. Standalone will almost always be faster.

Re: HTMLPurifier is too BIG ?
September 07, 2008 03:12PM

i can confirm that the standalone version is far faster & uses less resources on the server than the standard version. although we did need to change our minimum system requirements from PHP memory 8mb to 16mb minimum.

not a problem these days as such with PHP 5 only, because most hosts will use 16mb or more.. 8mb is very limiting with PHP5. PHP4 is dead news now anyway, and everyone should be using PHP5.

Quickquestion
Re: HTMLPurifier is too BIG ?
September 07, 2008 08:08PM

Ah ok thanks. I am trying to understand better how this works by reading the documentation and stuff. However, I am confused...what exactly does this "autoloader" thing do? Is it needed with the standalone. Also, if I want to make a new class to allow embeding like flash stuff, would I make a new file and include it after I include standalone.php (so I don't have to upload 500kb whenever I test a new version)?

Thanks

Re: HTMLPurifier is too BIG ?
September 07, 2008 08:18PM

Ok, so autoloader is a feature of PHP5, you should read about it here: http://docs.php.net/manual/en/language.oop5.autoload.php It is not needed for standalone, but can be convenient if you have your own classes in an HTML Purifier style directory. If you make a flash modification, you can put it in another file, yes, so you don't have to constantly reupload the standalone file. You SHOULD NOT modify the standalone file except in dire emergency.

Gonzalo
Re: HTMLPurifier is too BIG ?
December 22, 2017 04:41PM

Hello, i'm using HTMLPurifier version '4.9.3'. I have two problems, the first is that it is TOO big. PHP takes a lot of time to create the class, the second is that i have my own autoloader for my own libraries, and it is causing me troubles, how can i modify the HTMLPurifier scripts to work with my autoloader?

Re: HTMLPurifier is too BIG ?
December 22, 2017 10:01PM

Re (1), there's not really much we can do; HTML Purifier does a really thorough job and needs a lot of code to do it.

Re (2), here is the INSTALL guide's guidance on autoloading:

Autoload compatibility
----------------------

    HTML Purifier attempts to be as smart as possible when registering an
    autoloader, but there are some cases where you will need to change
    your own code to accomodate HTML Purifier. These are those cases:

    PHP VERSION IS LESS THAN 5.1.2, AND YOU'VE DEFINED __autoload
        Because spl_autoload_register() doesn't exist in early versions
        of PHP 5, HTML Purifier has no way of adding itself to the autoload
        stack. Modify your __autoload function to test
        HTMLPurifier_Bootstrap::autoload($class)

        For example, suppose your autoload function looks like this:

            function __autoload($class) {
                require str_replace('_', '/', $class) . '.php';
                return true;
            }

        A modified version with HTML Purifier would look like this:

            function __autoload($class) {
                if (HTMLPurifier_Bootstrap::autoload($class)) return true;
                require str_replace('_', '/', $class) . '.php';
                return true;
            }

        Note that there *is* some custom behavior in our autoloader; the
        original autoloader in our example would work for 99% of the time,
        but would fail when including language files.

    AN __autoload FUNCTION IS DECLARED AFTER OUR AUTOLOADER IS REGISTERED
        spl_autoload_register() has the curious behavior of disabling
        the existing __autoload() handler. Users need to explicitly
        spl_autoload_register('__autoload'). Because we use SPL when it
        is available, __autoload() will ALWAYS be disabled. If __autoload()
        is declared before HTML Purifier is loaded, this is not a problem:
        HTML Purifier will register the function for you. But if it is
        declared afterwards, it will mysteriously not work. This
        snippet of code (after your autoloader is defined) will fix it:

            spl_autoload_register('__autoload')

    Users should also be on guard if they use a version of PHP previous
    to 5.1.2 without an autoloader--HTML Purifier will define __autoload()
    for you, which can collide with an autoloader that was added by *you*
    later.


For better performance
----------------------

    Opcode caches, which greatly speed up PHP initialization for scripts
    with large amounts of code (HTML Purifier included), don't like
    autoloaders. We offer an include file that includes all of HTML Purifier's
    files in one go in an opcode cache friendly manner:

        // If /path/to/library isn't already in your include path, uncomment
        // the below line:
        // require '/path/to/library/HTMLPurifier.path.php';

        require 'HTMLPurifier.includes.php';

    Optional components still need to be included--you'll know if you try to
    use a feature and you get a class doesn't exists error! The autoloader
    can be used in conjunction with this approach to catch classes that are
    missing. Simply add this afterwards:

        require 'HTMLPurifier.autoload.php';
Sorry, you do not have permission to post/reply in this forum.