scrivo / highlight.php

A port of highlight.js by Ivan Sagalaev to PHP
BSD 3-Clause "New" or "Revised" License
695 stars 45 forks source link

Demo doesn't work - max execution time limit reached #41

Closed ostrolucky closed 4 years ago

ostrolucky commented 5 years ago

So, I just cloned the repo, did composer install, ran demo.php and:

PHP Fatal error:  Maximum execution time of 60 seconds exceeded in /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php on line 87
PHP Stack trace:
PHP   1. {main}() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:0
PHP   2. Highlight\Highlighter->highlightAuto() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:59
PHP   3. Highlight\Highlighter->highlight() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:577
PHP   4. Highlight\Highlighter->processLexeme() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:517
PHP   5. Highlight\Highlighter->processBuffer() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:315
PHP   6. Highlight\Highlighter->processSubLanguage() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:280
PHP   7. Highlight\Highlighter->setAutodetectLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:237
PHP   8. Highlight\Highlighter::registerLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:399

Fatal error: Maximum execution time of 60 seconds exceeded in /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php on line 87

Call Stack:
    0.0006     419552   1. {main}() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:0
   61.4569   36886696   2. Highlight\Highlighter->highlightAuto() /Users/gostrolucky/PhpstormProjects/highlight.php/demo/demo.php:59
   61.4964   36885896   3. Highlight\Highlighter->highlight() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:577
   61.5011   36888520   4. Highlight\Highlighter->processLexeme() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:517
   61.5012   36888520   5. Highlight\Highlighter->processBuffer() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:315
   61.5012   36888520   6. Highlight\Highlighter->processSubLanguage() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:280
   61.5039   36888712   7. Highlight\Highlighter->setAutodetectLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:237
   61.5039   36901056   8. Highlight\Highlighter::registerLanguages() /Users/gostrolucky/PhpstormProjects/highlight.php/Highlight/Highlighter.php:399
allejo commented 5 years ago

The demo.php file hasn’t been revisited in a while so it’s trying to highlight all 180+ code samples by detecting the languages automatically (which happens in a brute force fashion) on that page in 60 seconds.

At the top of the file there’s a call to set_time_limit(60) change that 0.

set_time_limit(0);

After that, the script will take a while but it’ll finish.

ostrolucky commented 5 years ago

I've already removed it, it didn't give impression I was looking for unfortunately. Feel free to close the issue. In your place I would fix the sample to alert user that this can take a while and/or change this limit there

AlexanderMatveev commented 4 years ago

I got same result:

in vendor/scrivo/highlight.php/Highlight/RegEx.php (line 79)

allejo commented 4 years ago

@AlexanderMatveev I've rewritten compare.php in 4ad052dcec50a4ca623026aab89ba24c93372bbe to behave better. I'm going to reevaluate whether or not demo.php is still necessary; it currently performs at least 34,225 highlighting operations on a single page load so that's why it takes forever. If you just want to see how well highlight.php compares to highlight.js, use compare.php.