I'm experiencing an intermittent error that I'd like some help debugging. I've seen this error both during cron runs and also when loading a lot of nodes, for example when using www.example.com/admin/content. I've also seen it when loading normal page-type pages. When this bug occurs as a result of a page load, I observe that the page fails to load and the following PHP error is printed on the page:

[16-Nov-2011 15:38:06] PHP Fatal error:  Maximum execution time of 240 seconds exceeded in <snip>/sites/all/modules/htmlpurifier/library/HTMLPurifier/Strategy/MakeWellFormed.php on line 493

When it occurs during a cron run, I only see this error in my PHP errors log. I have tried clearing my HTML Purifier cache, but this does not seem to help.

I added dpm($old) immediately above line 493 in MakeWellFormed.php and observed that this function is called many hundreds of times while loading admin/content, all with empty $old. Is this the expected behavior? Any ideas about why this is happening on my site or directions I can look to figure it out?

Thank you.

CommentFileSizeAuthor
#6 drupal_debug.txt328.75 KBsdrycroft
#2 signature.png52.26 KBaddicted_to_drupal

Comments

ultimike’s picture

Version: 7.x-1.0 » 7.x-2.x-dev

I have been seeing the same behavior...

-mike

addicted_to_drupal’s picture

StatusFileSize
new52.26 KB

I had the same problem, i went on the net and after a lot pages i found this one

the soluce

And it works. You have to go one location of drupal/sites/default folder then found the file defaulf.setting and add new line on it

ini_set('max_execution_time', 0);

You can also use others one like
ini_set('session.cookie_lifetime', 2000000);
it's as you wish

I hope it help's you

ezyang’s picture

Status: Active » Closed (won't fix)

HTML Purifier is something of a time-and-space hog. Unfortunately, there's not much I can do to help you here unless you can identify the specific content which is causing problems.

sdrycroft’s picture

Status: Closed (won't fix) » Active

I too am experiencing this same error. addicted_to_drupal's suggestion is NOT a good one, and should not be used on a production site.

heddn’s picture

Version: 7.x-2.x-dev » 7.x-1.0

Can you provide details please? Specific html content and some context?

sdrycroft’s picture

StatusFileSize
new328.75 KB

Attached is the problematic HTML.

sonicthoughts’s picture

same issue. CPU pinned to 100% and failed after 60 seconds on a big machine. note that the page was also 2000 lines of html, but this is a problem....

robmalon’s picture

Version: 7.x-2.x-dev » 7.x-1.0

Same thing here. I've noticed this particularly on admin/content when the newest nodes in that list have more than usual html markup cumulatively. Likewise, on individual node view/edits that have a ton of markup via tables (similar to sdrycroft's). Raising the timeout limit or removing it solves the problem in some cases after 10 minutes, but that's not something I'm willing to do on production. Unfortunately that makes this module a deal-breaker for me. I can see my users submitting content, going nuts with the markup, and crashing my server :-\

I DO however have some lengthy configurations. The one that stands out is HTML.Allowed which is (note I forced 2 line breaks to fit it on the page nicely):

p[align|style|class],strong,a[href|title|rel],em,table[class|width|cellpadding],td,tr,h2,h3,h4,h5,h6,
hr,br,u,ul,ol,li,img[src|width|height|alt|class],span[class],strike,sup,sub,div[class],code,del,blockquote,
q,cite,dt,dl,dd,b,th,tbody,thead,tfoot,colgroup,caption

Maybe if I slim this down things will go smoother.

sdrycroft’s picture

I agree with heddn's comment on #1831196-3: 7.x-2.x Roadmap - this really needs fixing at the library level. It would be nice if this module were able to monitor the progress of the library, and kill it if it's taking too long (I realise this would be far from easy to implement).

jay.dansand’s picture

We solved worked around this issue by imposing a 10-second execution limit, checked via AJAX on form submission. Our theory was that if HTML is too complex to be parsed within that time, it should be refactored by the author. For example, instead of submitting an entire book as a single body field, it could be broken up by chapter into smaller, digestible chunks. Or, if it can't be reasonably refactored, one of the webmasters should be contacted and we can review the code and post it as Full HTML (which doesn't invoke HTMLPurifier), or maybe some other type of compromise can be made.

The method is, basically, when a filtered HTML field is submitted:

  1. JavaScript halts the form
  2. An AJAX request is submitted against our endpoint, call it "testpurifier", containing the field content and the selected filter format
  3. The callback function for "testpurifier" sets the time limit to 10 seconds, and then uses check_markup() to invoke HTMLPurifier against the submitted field content
  4. If the callback function is not aborted due to PHP exceeding the execution time limit, it returns a "success" JSON object
  5. The JavaScript in the client's browser waits for a reply or timeout from the server, and reacts according. If it gets a "success" result, then it allows the form to submit. Any other result is considered a timeout error: the form is prevented from being submitted and the user is given an error message.

Yes, JavaScript is required for this approach to work, but we're mostly using CKEDITOR anyway so that's not an added requirement. I can share the module if there's any interest in this sort of solution.

heddn’s picture

Status: Active » Postponed (maintainer needs more info)

Please provide the working solution. I'd like to see if we can incorporate it into this module.

heddn’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

@jay.dansand please re-open and kindly provide more details. Otherwise there's no means to resolve this without more info.

sdrycroft’s picture

Status: Closed (cannot reproduce) » Active

The HTML I provided in comment #1344664-6: PHP Fatal error: Maximum execution time of 30 seconds exceeded in MakeWellFormed.php will allow you to reproduce the original error. I'm happy that this should be fixed at the library level, but that doesn't mean that this issue should be closed. If anything, this issue should be marked as "postponed" with a link to a bug report on the library's issue reporting system.

heddn’s picture

That makes sense. I was looking at #10 for a potential solution but if you want to open an issue upstream @ http://htmlpurifier.org, go ahead and move this to postponed.

jay.dansand’s picture

Sorry for the late follow-up! I work in higher-ed so my developing time is dictated by the demands and vagaries of the school year. Our solution's co-developer (a bright student at my university) currently has the job of cleaning up the code to be worthy of a Drupal.org submission, at which point it'll be released.

I think the high-level description in #10 is probably enough to build the work-around from scratch, but admittedly that's a fair bit of redundant (wasted) effort: it'd be way better if we could get our version cleaned up and into the community. We're working on it and we'll post again as soon as the code is available.

isolate’s picture

We had a similar problem. This patch in htmlpurifier fixed it for us: http://repo.or.cz/w/htmlpurifier.git/commit/54477c172b31ff69f6d9bc0c6652...

heddn’s picture

Issue summary: View changes
Status: Active » Fixed

Looks like a fix was provided upstream. Marking as fixed.

Although I'd be interested in looking at the solution that @jay.dansand has as well.

jay.dansand’s picture

I don't think it's cleaned up enough for a Drupal.org project submission, but it works. Here's the sandbox: https://drupal.org/sandbox/tuanc/2033663

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.