Sudden empty / blank page for large posts with WordPress

Sudden empty / blank page for large posts with WordPress


It isn’t fair: you spend a few hours on creating your most marvellous blog post ever, the one and only that will surely enlist you in the Hall of Famous Bloggers, but then you click Publish or Preview and all you see is an empty post. Totally panicked you click “Edit” (never do that!) on that empty post only to find yourself in an editing screen that’s, well, empty (!!). Before you try to commit suicide, I hope you do a bit of googling and find yourself here or on one of the many other helpful / not so helpful posts on the subject.

Because googling didn’t help me (I tried them all), I present you here with what I believe is the ultimate solution. After I located the real culprit I was able to do a bit more to the point searching on the Net and suddenly found some other posts on the same subject closing in on a good solution. See references section for others posting on this subject.

The problem: empty page with only header and footer for a large post

Update: this problem can also occur if you do not use any shortcodes, after a clean install of PHP and WordPress !

In my case, the post needed to be reasonably long. The post also needs to have shortcodes (or short-tags), like [mycaption]some caption[/mycaption] or [mygallery source="galley" /] (remove “my”, see note). As soon as you place a picture with a caption on your page, you have shortcodes, possibly without even knowing it. If the text after the shortcodes contains newlines and the shortcode itself is surrounded by newlines, the problem may kick in which results in a page that is without any content (see screenshot), without any error but with the header, the footer, the title, the edit button etc.

Screenshot of no content for a large post in WordPress

Screenshot of no content for a large post in WordPress

This same behavior occurs already if you click the Preview button so you may see the problem before actually publishing.

My blog post about how to determine debug or release build was my first encounter with this problem. If you want to test whether your blog or blogosfere is vulnerable for this bug, you can download / view the content of this post. Just paste it in a new blog post (in HTML view) and click Preview Changes. If it shows an empty page, this can happen to you too in which case you should check the fix provided below.

A note on shortcodes

Shortcodes are nice additions to make editing easier without knowing much XHTML. They are available since WordPress 2.5, but so far the implementers have forgotten to add a method to escape the shortcodes. One of the larger blogs about the subject doesn’t even mention it, nor does the original API doc. If you look through the code, there’s been some thought about using double [[ and ]], but this has never been applied throughout all the code. Someone thought to come up with a plugin No Short Code which adds a new shortcode that disables the shortcodes inside, but unfortunately, that only works occasionally and it doesn’t work at all from the editor (try using wpNSC with the [_gallery_] shortcode, the effect is terrible). I changed the names of the shortcodes above to rubbish shortcodes, because if I used a registered shortcode, they wreak havoc to my page.

The solution: a simple fix prevents this blank page bug

EDIT: original solution was the shortcodes fix below, but it didn’t work in all cases. Instead, the actual cause of the problem is the limit of the regular expression recursion depth as explained below. This limit is way too restrictive and causes a hard crash of your page, depending on size, use of shortcodes and use of other plugins that also employ regular expressions.

Do the following to fix this problem:

  1. Open PHP.INI in a text editor of your choice (normally you can find php.ini in your php install dir)
  2. Change the recursion limit to 200x normal, that is, set: pcre.recursion_limit=20000000
  3. Change the backtrack limit to 100x normal, that is, set: pcre.backtrack_limit=10000000
  4. Stop and start the Apache (or IIS) service

This increase will hardly have any effect on the performance. Placing it much higher is not a good idea, as running a neverending faulty regular expression is possible and should be resolved, otherwise it will take too much memory or performance, neither are good.

Please drop me a line if this fix does not work for you and when the problem is similar.

Alternative solutions

Below are a few solutions that I tried along the way. I added them, because they didn’t work for me or only worked for a short while. The first one, about shortcodes, solves the issue in many cases, but does not solve the core problem: not enough depth for the regular expressions.

Shortcodes fix

EDIT: this was my original solution, it will work in the majority of cases, but as explained above, you can solve this better by not changing the source code of WordPress.

As explained above, the cause of all this is the way default shortcodes are treated in the formatting.php source file. To fix this behavior, simply uncomment the line that’s at the end of the wpautop() function in the formatting.php file, which you can find in the wp-includes directory. For WordPress 2.8, this is line 173:

// in function wpautop in file wp-includes/formatting.php
// next line is line 172
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );

// AB: comment the following line to prevent blank page bug:
//$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone

return $pee;

The effect of removing or commenting that line is almost nothing in most cases. It is used by the default filters which are called when apply_filters is called and expression replaces the content that’s wrapped inside shortcodes which got an extra <p> earlier on and removes this <p> to prevent unwanted paragraph whitelines around shortcodes. The line has been around for a while and this bug too. There’s a post on the wp-pro list about this line not giving a too clear an answer, and there’s this other post that contains a bit more detail about this bug altogether. It being reported so long ago, it doesn’t seem that anybody at the WordPress developer team is going to fix this bug sometime soon.

Stop using [ caption ] shortcodes

Reading on about this issue you may have encountered that some people consider the [ caption ] shortcodes to be the problem. By not using them (and painfully typing in the HTML code by hand) they get around this bug. But the bug could easily occur in any other situation using shortcodes.

Remove the filter wpautop

Using the line remove_filter(‘wpautop’) you can remove the wpautop filter altogether. Some people prefer this as it gives them more control over the whitespace handling of a post. Removing this filter has the effect that whitespace becomes insignificant and that you’ll have to add paragraph <p>…</p> tags yourself for inserting whitelines.

This fix feels for me like using a bulldozer for hoeing your garden. This fix has so many nasty side effects that all my existing posts become illegible and that’s not really what we’re after here…

The cause: a bug in the regular expression engine of PHP

Update: this is not really a bug, it is more a matter of very low and unrealistic default settings, see solution amd recursion limit of PCRE.

The actual cause of this bug seems more complex than it appeared at first sight. The regular expression does its thing in all but a few cases. Then, if you take the text from the download link and you remove one letter from the end of it, the post renders correctly. Also, you may notice that when you remove the /s modifier of the regular expression like in the following code snippet, the problem goes away as well:

// the /s removed works well too
$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/', '$1', $pee);

The /s modifier makes the match-all dot to match everything, including newlines. Without the /s modifier, the dot does not match newlines, i.e., the complete match does not span multiple lines. Let’s look a bit closer to the match when the get_shortcode_regex function is applied (this function can be found in wp-includes/shortcodes.php):

// the shortcode regex (abbreviated, spanned across multiple lines)
$pee = preg_replace('/<p>\s*?((.?)\[
TEST|gallery|code|anyshortcode|etc)
           \b(.*?)(?:(\/))?\]
           (?:(.+?)\[\/\2\])?(.?))
           \s*<\/p>/',
           '$1', $pee);

If you’re familiar with regular expressions it shouldn’t take you too long to figure out what the above does. It looks for texts of the following forms and removes the <p> and </p> from it:

<!-- NOTE: remove underscore, _caption becomes caption etc -->
<!-- before regex -->
[_caption]hello I am a <p>caption</p>[/caption]
[_gallery value="<p>something</p>" /]

<!-- after regex -->
[_caption]hello I am a caption[/caption]
[_gallery value="something" /]

When you test the regular expression in a test environment, it works pretty well. Why it doesn’t work in this or some other situations is beyond me. The only reason I can think of is that the numerous backtracking reaches some internal limit on large posts, which is where and why it starts behaving oddly. However, reaching any such limits without throwing any error is highly unusual.

If you read this and you can shed some light on this issue or you know of a better fix, or you’re a core WordPress Developer and you know what’s going on, then don’t hesitate to drop me a line.

Meandering about large blog posts on WordPress

It’d be unlikely a big surprise that my first and foremost thought was “WordPress does not allow big posts, help!!”. As you can read from the previous sections, this proofed wrong. Yet I’d like to share a few of the things I found out during my searches, it may help you next time you think large posts are the cause of your issues. Here’s a summary:

Apache and HTTP POST limits

In all but a few cases, WordPress runs under a LAMP, WAMP or MAMP environment, which all have in common that Apache is the HTTP daemon that serves the PHP pages of WordPress. Apache has limits, but they are few:

  • Apache limits internal redirects. Redirects are used with friendly and permanent urls in WordPress. The limit is defaulted to a maximum of 10 redirects on the same server. Surpassing this limit will show up in the logs as an error. See LimitInternalRecursion directive.
  • You can limit the length of the request body. The default is unlimited, however. Unlimited in this sense means 2GB which in practice means that you cannot upload files larger then 2GB. See LimitRequestBody directive for details.
  • There’s a fixed limit for XML Request Bodies. This is the body that’s used for XMLHttpRequests and this method is heavily used by the WordPress page editor and others to send intermediate updates to the server (to prevent work loss). The maximum here defaults 1000000 bytes, which is close to 1 MB. It is possible that posts exceed this limit, though unlikely. In my case, I wasn’t even close. See LimitXMLRequestBody directive for details.
  • There are other limits, like the limiting the size or the amount of HTTP headers through LimitRequestFieldSize/LimitRequestLine (both default 8190 bytes per header value/line) and LimitRequestFields (default 100 HTTP headers) but these have little to do with the issue at hand.
  • By default, Apache is not limited to the amount of memory it can consume, but you can configure this differently on a per thread basis.

PHP limits for HTTP Post and file uploads

Where Apache has its limits set very wide (and righteously so, it must support many types of server software), PHP is must trickier when it comes to limits. As it turns out, the following limits apply to a default PHP installation:

  • The maximum time a script can take to respond is 30 seconds by default. You can set the variable max_execution_time in php.ini.
  • The maximum time a script can spend in gathering request data (related to upload time from client to server) is 60 seconds, it can be set with max_input_time.
  • Any script can consume 128MB as a limit, but multiple requests and scripts together can add to that limit unlimited.
  • Upload file size is limited to 2MB by default. This is not very much, but does not interfere with large HTTP POST requests. Set the upload_max_filesize setting to change this.
  • HTTP POST size is by default maximum 8MB. It is unlikely that I reached that limit (the size of the POST was about 25kB). You can change this setting by editing post_max_size in php.ini.
  • There are other limits that deal, for instance, with database persistence. By default, all these limits are set to no limit.
Limits of PCRE, the regular expression engine used most by PHP

The Perl Compatible Regular Expression engine, in other words, the engine that takes care of the regular expressions that are used inside the filters of WordPress, has its own limits and maximums. By default, these are very high. It is unlikely that you ever need to set these higher then the default. I haven’t tested with different settings, if I find anything, I’ll update here.

  • The limit for backtracking, pcre.backtrack_limit, defaults to 100000 (100k). This limit is the maximum number of backtrack positions a regular expression does when using greedy regular expressions.
  • The limit for recursion, pcre.recursion_limit, defaults to 100000 (100k). It is difficult to predict recursion depth as it highly depends on the expressions, but in general, recursion increases when you use nested quantifiers. Another term for recursion limit is stack size limit.

Side note: PHP has three different regular expression engines, but the preg_* functions all use the PCRE library, which is the most versatile and fastest of the three. If you want to know more about these flavors, I suggest you get yourself a copy of Jeffrey Friedl’s Mastering Regular Expressions.

Conclusion

WordPress is a lovely though rather simplistic environment. The simplicity stems from its heritage with PHP and with the impossibility to do structured programming or proper debugging. PHP adepts will tell you that both are very well possible, but the main cause for errors like these is that structured text is approached with unstructured tools. Valid structured XHTML is approached with regular expressions that are applied on top of one another. Even a mastermind cannot follow the course of a content string throughout the WordPress code and explain from looking at it how the contents will change or how it will conflict with other parts of the code (other filters). Luck, trial and error and a whole lot of stamina from the tiredless developer’s community has proven the best medicine against a poor design and a poor choice of programming language.

And let’s not forget, amateur programmers love PHP (and to a lesser extend Ruby, Perl or Python). Without these amateur programmers there wouldn’t be such a lively community and such a — to a certain extend stable — implementation of blog software.

This was just a single bug and it showed me some of the inner workings of WordPress. I haven’t gone too deep into the details this time as I just wanted to provide a little context to the problem. This look at the code hasn’t made me any more enthusiastic, but I’ll continue using it (using is different then building it) as it is definitely one of the best in its kind in spite of its shortcomings.

References

Selection of some of the more a less relevant references. Not all references from the text are cited here, if you feel you’ve been the originator of some of my ideas that I explained, drop me line and I add a reference to your site as well:

History

A little history of this page, only major updates are included. Check here if you want to know whether anything has changed since your last visit here.

2009-09-29 added and corrected some links, improved some parts of the text, added history overview
2009-09-04 updated the text on php.ini, added workarounds
2009-09-03 changed order of the story-flow, added quick-nav menu
2009-08-30 changed text dramatically to move php.ini PCRE solution to the front and older solution further back
2009-07-31 added php.ini solution on PCRE recursion limits, researched new solutions, updated large parts of the text
2009-07-08 initial post on [ shortcode ] problem and fix in core WordPress files


– Abel –

  • http://twitter.com/twittingpedro Peter Bacani

    Hey, just wanted to say thanks the recursion and backtrack solution worked for me! Just added those lines and restarted my xampp for mac and it just worked.

  • Maky

    I have been using wordpress on this site since last 7-8 years I guess and had no problem.

    Now suddenly since last few months I am facing a strange problem. I get a blank white page

    - when I edit an existing post and click preview changes

    - while creating a new post it gets stuck on saving draft (auto save)

    - white blank page when I save draft

    - white screen when I edit and publish a post

    - white screen when I publish a new post or delete a post

    I tried deactivation and deleting all plugins, but it still occurs.

    I tried using default latest twenty eleven theme, but it still happens.

    I installed WP-DBManager and cleaned and repaired my database too.

    I deleted all the wordpress files (except wp-content) and installed it fresh – with no effect.

    I even changed my webhost.

    It looks to be a problem in database structure or something.

    I have around 982 published posts, 5 pages, 30 categories, 348 tags

    and database size is around 34Mb.

    I tried adding
    ini_set(‘pcre.backtrack_limit’,10000000); ini_set(‘pcre.recursion_limit’,20000000);
    in php.ini, fastphp.ini and wp-config.php but with no success.
    I am on shared host and my other more than dozen websites on wordpress are working fine on the same server.

  • Pingback: blogpost README | Alexey Mints homepage

  • Nitin

    Thanks so much! Changing the limits worked like a charm. I am on shared hosting. So, I could not change the php.ini. I added the following lines to wp-congif.php:

    ini_set(‘pcre.backtrack_limit’,10000000); ini_set(‘pcre.recursion_limit’,20000000);

  • http://twitter.com/nikitasmits Nikita Smits

    Hey!

    Any chance you can help out with people who have this problem when using wp.com?

    It just happened to me with a post.. :(

  • Naja melan

    suhosin.post.max_value_length can also limit the lenght of the post_content value. The problem can also be more obvious when people copy an image and then paste it in the editor. Tinymce supports this and creates data:image/… url’s. That’s nifty, except for the fact that the size of the images becomes more than 5 times as big. That means that if you have a long article with 5 images of 100kb, your article might be approximating 3MB. It is probably good that php stops you from adding 3MB rows to your database, knowing that wordpress keeps revisions of all articles when they get edited and those revisions are simple copies of those database rows. That would add up in clunky chunks of 3MB every time you changed even 1 letter in the article.

  • Pingback: Post Size Limit | Q&A System

  • Pingback: Fast Pixel-Perfect Collision Detection for Cocos2D with Example Code (1/2) | Learn & Master Cocos2D Game Development

  • Pingback: Post Size Limit | SeekPHP.com

  • http://cafeforex.ru/ Ivan

    Forgot to tell, deleting the wpautop filter don’t solve the problem in version of the WordPress 3 or 2.9 I think.

  • http://cafeforex.ru/ Ivan

    Thank you! It’s great! I thought, that the problem in one of my plugins, but not!

    It’s really:
    pcre.recursion_limit = 20000000
    pcre.backtrack_limit = 10000000

    I added it into my php.ini and all work now!

    And I have a Big post:)

    I’m so happy, that I waste only 30 minutes and found your site so quick!

    • http://pointdesi.com pointdesi

      that exactly what happened to me. but now this method is so simple and easy. just copy paste the above code to your root php.ini file and enjoy running long text posts.
      If could not find create a new one with only code below inside it.

      pcre.recursion_limit = 20000000
      pcre.backtrack_limit = 10000000

  • http://www.format78.de Björn

    Some apache servers have the suhosin patch installed, which caused the same error in my case.

    There is a too small value for suhosin.request.max_value_length

    I needed to ask the hoster to change it.
    bw, Björn

  • http://stealherstyle.net Linda

    Thanks so much for this post. I just went for the simplest solution which was to remove the captions because they weren’t really necessary, but without your post I would not have known that the captions were the problem.

  • http://www.learnopengles.com Learn OpenGL ES

    Thank you for posting this! I was wondering why the long post I was working on suddenly started to become blank. I added the code to the PHP.INI as well as the WP-CONFIG.PHP as per the suggestions of another commentator.

  • http://patorjk.com/ patorjk

    I just want to say thank you for making this post! I was totally perplexed when my post showed up blank. After toying around a bit I found that if I cut down on the length of my post, it’d show up, but this didn’t make any sense to me since I knew I had written longer posts. Anyway, I ended up going with the solution you proposed on removing the “[ caption ] shortcodes” and it fixed the issue. Thanks!

  • Al

    Hey,

    I did everything you mentioned but I can’t find where to restart apache. I’m using hostmonster. You wouldn’t have any idea would you?

    I’ve emailed them anyway.

    • http://undermyhat.org Abel Braaksma

      Unless you have remote root access, you cannot restart Apache yourself. See the comments from “Floridan” for a method to change these settings without restarting Apache (note that his suggestion doesn’t always work).

      Also, if your hosting provider offers you the cPanel web interface, you can set these settings through its interface.

      • Al

        Thanks Abel,

        The florian method didn’t work.

        I have access to the cpanel. I changed the php.ini etc. but nothing changed.

        After looking at my problem with WordPress, it seems that adding more characters isn’t a problem, but the moment I add another bit of html or shortcode the page disappears. It was adding all the link html (I had a lot of links pointing to wiki) that seemed to overload it.

        I’m corresponding with the host provider, so hopefully they’ll be able to supply a solution.

        • http://undermyhat.org Abel Braaksma

          From your description, your problem seems indeed related to what’s described in this thread. Let’s hope your hosting provider can do a restart of Apache for you.

  • http://www.beatlesbible.com/ Joe

    I stumbled upon this page while having the same problem with blank pages (ie header and footer showing, but no content, and nothing saved). It turned out to be nothing to do with shortcodes, but the Suhosin PHP extension. A setting on that was limiting posts to a max of 64kb; anything over that would cause an error when saving. Disabling or amending Suhosin was the only solution.

    I thought I should point this out in case others are having the same problem and think it’s definitely due to shortcodes. It may not be.

    • http://undermyhat.org Abel Braaksma

      Hi Joe,

      That is correct, there are many causes that result in empty looking pages. In essence, it’s a PHP problem and any WP extension, if badly written or tested, may have this effect. I do not consider shortcodes an extension though, which makes this a WP/PHP issue to me.

  • http://juegosimportados.com Jordi

    Thanks so much! many hours

    After many hours lost,I was somewhat desperate about this “bug”, but after discover this post my life has meaning again :p

  • Pingback: JoshMcCarty.com » Fix: WordPress Post Content Disappears with Too Many Shortcodes

  • http://www.EasyEarTraining.com Christopher Sutton

    Just wasted 20 minutes trying to figure out this bizarre problem with a post – but then your solution (changing the PCRE limits in php.ini) worked like a charm. Thanks for bothering to write it up!

  • http://www.consultingrehab.com Ryan

    Thank you!! Just wasted 3 hours of my life trying to figure this out.

    I’m on a shared server with BlueHost, but the php.ini fix worked perfectly even without any sort of server reset (sadly, that’s the last thing I tried…)

    Thanks again for putting this together!

  • http://pffmihai.com pffmihai

    I was too working on a client page with lots of shortcodes so he can easily edit the page contents and i was in the same position.

    Using these two lines

    ini_set(‘pcre.recursion_limit’,20000000);
    ini_set(‘pcre.backtrack_limit’,10000000);

    in the wp-config.php worked like a charm.

    Another note on the code, beside the fact that it doesn’t require the apache restart, is that you have to make sure you change the quote marks in that as wordpress comment system replaces the quotes in a funny way.

    Thank you for the solution.

    • http://www.undermyhat.org Abel Braaksma

      Yes, that suggestion (using init_set) was suggested before, I should add it to the post, thanks for reminding me :)

  • Floridan

    Hi Abel,
    I posted this over at WordPress.org and I would like to re-post it here for those readers who had no success with your fix.

    Some of you have reported issues with blank pages if your posts are too long or contain too many comments. I had the same problem with disappearing posts until Rob in tech support at Liquid Web helped me to resolve the issue. I tried Abel’s fix over at http://www.undermyhat.org/blog/2009/07/sudden-empty-blank-page-for-large-posts-with-wordpress/ but I had no success.

    Then Rob came up with the solution after about 45 minutes of troubleshooting. The fix is to increase the memory limit in your wp_settings.php file which is found in your server root. The number below worked for me! I’m a happy camper now. :)

    if ( !defined('WP_MEMORY_LIMIT') )
    define('WP_MEMORY_LIMIT', '48M');

    • http://www.undermyhat.org Abel Braaksma

      Hi Floridan,

      That’s a great suggestion. Of course, if you change the recursion limit it won’t help you if that limit ends up needing more memory than the global setting allows you to use. It never occurred to me, my global setting was very high from the start. Thanks for sharing!

  • http://www.youlinchng.com YouLin

    Hi, Abel,
    Found your useful blog via search. I am having this problem since months. And this week I installed WP ver3.0, and it is getting worst and mess up my whole blog. I just realised that a bug on wordpress ver 3. I am wondering wheather your solutions(since it’s quite long from now)can apply to the current problem?

    • http://www.undermyhat.org Abel Braaksma

      Youlin, I haven’t upgraded to 3.0 yet. It’s a major new version and I tend to wait before it reaches full maturity. Your post warns me that I should be careful. Unfortunately, I cannot advise you, other than rolling back the backup that you made (I hope!) before upgrading.

  • http://fran@fransheirlooms.com Rob Quinn

    Thank You! Thank You! Thank You! I a freakin’ geek and have be tearing what little hair I have left trying to figure out why changing some minor text on my wife’s doll site was causing the page to go blank. I owe you a beer.

    • http://www.undermyhat.org Abel Braaksma

      Beer’s always welcome :) ! Come visit me when you’re around!

  • http://www.beruly.com Anne

    THANKS A MILLION!! We were really banging our heads against the wall until we read your post. You are a saint! Your fix worked great!

    • http://www.undermyhat.org Abel Braaksma

      I just looked in the mirror and saw that sainty aureole above my head ;-)

  • http://www.taller.carlosfumagalli.com.ar fum

    I want to add a detail that I forgot:
    support people asked me to show you an example of the problem input, so I made a large entry to show the issue.
    Then when I only have included a very large text the problem not appears, the entry was normal published.
    How is it I thought?
    When I added an singlepic with nextgen gallery shortcode, I got the trouble, the full entry disappears.

    • http://www.undermyhat.org Abel Braaksma

      Then Nextgen is the cause here. It uses regular expressions. So: ask the support people to make the recursion limit in php.ini higher, possibly referring them to this page.

  • http://www.taller.carlosfumagalli.com.ar fum

    Hi,first thank you for publish your work, I got exactly the sensation you said when I sow that my laborious entry does not appear in my blog.
    I tried to solve the trouble contacting the support hosting people and they said that has modified the recursion limit of PHP.ini according to your instructions. But nothing change.
    Any suggestion about this?

    In other way, I tried the alternative solution and I have looked the formating.php and sought the code line you said, but can’t find it. There are about twenty similar lines but not exactly this. I’m using WP 2.9.2 and your example is over 2.8 can you tell me how to find the equivalent?

    I’m very gratefull if you can help me, greetings, and sorry for my horrible english.

    • http://www.undermyhat.org Abel Braaksma

      Hi Fum,

      There can be many causes if the above didn’t help you. First check whether the reason for the issue is equal as in this thread: change your page to something smaller. Does it still end up empty? If your smaller text appears, then the recursion limit is likely the cause. But when you have a faulty plugin that still reaches the new recursion limit, then you may end up choosing between two bads: either remove the offending plugin (if you can find it) or make the recursion limit even higher, possibly taking up too many resources on your machine.

      If the above doesn’t help and your text ends up empty regardless, your issue may be unrelated.

  • Locke

    I’m confused here. Is the php.ini file the one located within on my dedicated server. usr-lib-php.ini or is this file an individual file in each wordpress install.

    If its on my dedicated server do I simply add the two codes to the very top of that file. My php.ini file starts like this. so where do I put the code? thanks

    [PHP]

    ;;;;;;;;;;;
    ; WARNING ;
    ;;;;;;;;;;;
    ; This is the default settings file for new PHP installations.
    ; By default, PHP installs itself with a configuration suitable for
    ; development purposes, and *NOT* for production purposes.
    ; For several security-oriented considerations that should be taken
    ; before going online with your site, please consult php.ini-recommended
    ; and http://php.net/manual/en/security.php.

    • http://www.undermyhat.org Abel Braaksma

      Hi Locke, just locate the line that has pcre.recursion_limit in it (use Search of your editor) and update that line. Don’t forget to restart your web service (machine can remain online, just restart Apache or whatever you use).

      • Ease Beats

        there is no pcre.recursion_limit…..

        • http://undermyhat.org/ Abel Braaksma

          If it isn’t there, then it has the default value, which is quite likely too low. You can add the line safely.

          • Ease Beats

            where will i add it to i mean under what heading will i place the pcre.recursion_limit?

  • http://www.medicaldentalfs.com Ray Prince

    Hi

    Thanks for this fix!

    I accessed my php.ini through cpanel, clicked on edit and then inserted the code as exactly below at the top of the php.ini page:

    pcre.recursion_limit=20000000
    pcre.backtrack_limit=10000000

    I’ve been looking for over a week for this so again, thanks v much!

    Ray

    • http://www.undermyhat.org Abel Braaksma

      You’re welcome. Glad to know you can change this through cPanel as well. You may want to check the file for more occurrences of the same. Not sure what line would be leading when it’s already there (often it is).

  • Nora

    what would be the solution to this problem in wp 2.9.1?

    tnx

    • http://www.undermyhat.org Abel Braaksma

      Apologies for missing your comment earlier on. I’m running WordPress 2.9.x and the fix still works (the fix is at PHP level, not really at WP level, so it should work for any future version). Can you elaborate what your issue is if it doesn’t help?

  • Pingback: johnjcamilleri.com » Empty / blank page for large posts with WordPress

  • http://johnjcamilleri.com John J. Camilleri

    Tried your php.ini fix, it worked great first time!
    Can’t express how thankful I am for finding this post! :D

    • http://www.undermyhat.org Abel Braaksma

      Glad it worked out so easily en glad you were able to find me ;-)

  • http://www.sertalpbilal.com Sertalp Bilal

    I don’t get the idea.
    Will I upload php.ini to my wordpress folder after I edit it?

    • http://www.undermyhat.org Abel Braaksma

      If you can’t access php.ini because you’re in a hosted environment, try to use the tip mentioned in this comment to do it in PHP code instead. Or check the comment just below this one, where another user shows how you can do just that through code.

      Sorry for a late reply, missed your comment earlier on.

  • http://songdogtech.net songdogtech

    Another fix, if you don’t have access to php.ini (according to this thread at WordPress forums) is adding these lines to the top of wp-config:

    ini_set(‘pcre.recursion_limit’,20000000);
    ini_set(‘pcre.backtrack_limit’,10000000);

    • http://www.undermyhat.org Abel Braaksma

      Thanks for mentioning it. Actually, it’s on this page as well, however slightly hidden in this comment by me.

      Note that the ini_set only works if it isn’t prohibited by your provider. Usually when they limit access to php.ini they also limit access to ini_set.

    • http://iki.fi/o Olli Niemitalo

      Ahh, great, thanks! I had problems with my long post not displaying after publishing. Added those two lines and now it works, even when my page is on a web hotel and I have no write access to PHP.INI.

  • http://WhitchurchArts.org.uk Andrew Reeves-Hall

    I updated the php.ini file that was in my home and WordPress directory with the two lines suggested here – presto! My blog was immediately fixed! Thank you!

    ~Andrew~

  • Joe

    Thanks a lot, your fix on php.ini works nicely.

  • http://www.teddy-o-ted.com Teddy

    Thank you! I was experiencing the same problem too when I was penning the latest post – when nothing seemed to be amiss in the WYSIWYG editor, whenver I load the post preview I am served with blank post content. I initially suspected that there’s a problem with the HTML codes but validation using W3C’s site showed nothing wrong. I reduced the number of captions and it worked, but wasn’t very sure how could we prevent that.

    The php.ini method worked perfectly well for me! I’m not sure whether my host will kick up a big fuss about that, but so far so good :)

    Thanks for the fix!

  • http://hikari.ws/informacao/666/anthony-galli/ Anthony Galli

    Hey dude thanks a lot for the tip!!

    I had the same issue here, a large post was showing empty!

    I’ve used this php.ini config and it is now working. But I can’t use php.ini, so I used .htaccess to change it.

    I’ve narrated my “little adventure” in my site too :)
    WordPress Large post showing blank / empty?! NO WAY!!

    Tnx for sharing your experience.

  • Brett

    THANK YOU THANK YOU THANK YOU!!!! I appreciate the post, and knew someone would have the solution. I almost went crazy, then you saved me! All I had was 3 articles inserted onto 1 page using bluesome’s PHP plugin and some WordPress get_post code. Depending on the length of the post, things would show or disappear all together. All is right with the world again!

    • http://www.undermyhat.org Abel Braaksma

      I know exactly how you felt, you don’t want to know how long it took to find the actual culprit of this nasty little scamp. Though the final solution is easy, debugging a crash that isn’t really a crash in a language that cannot be debugged is just terrible. Glad it helps so many people, makes it worthwhile! ;-)

  • Dennis

    Great! you saved me spending some more hours (way too many already) on this problem! Had the same problem: too many shortcodes. Applied the PHP.ini PCRE settings and now it works like a charm! Thank you!!!

  • http://revista.peruanosenusa.net Aldo

    In my case, large posts, when displayed, where blank (no text). I had some shortcodes, not a lot.

    I can’t change php.ini since we are in a shared server.
    So I went to formatter.php … and the line was already UNCOMMENTED. I’m using WP 2.8.4.

    So I COMMENTED OUT the preg_rep line instead, and that solved my problem. Seems that line is going to deep in recursion or something like that and causing a memory problem for large posts (in my case, ~2000 words will trigger)

    • http://www.undermyhat.org Abel Braaksma

      A possible workaround, if you can get to the PHP code: you can use the ini_set() function and place it somewhere in your settings.php. The ini_set() function allows to override PHP.INI settings programmatically.

      Another alternative is through Apache config files if you have access to those.

  • http://It'snotworking.. gamersroute

    Darn. I really hoped that this could fix it.

    I’ve tried both fix, even with php.ini trick.

    I’m on 2.8.4.
    My post is about 11,000 words.

    • http://www.undermyhat.org Abel Braaksma

      Have you restarted your Apache service after applying the PHP.INI trick? You can contact me at abel.blog@xs4all.nl if it still doesn’t help, I’d like to help you resolving it and edit this post with any new insights.

  • http://paulanealmooney.com Paula Neal Mooney

    Woo! Thank you Jesus for posting this.

    I just wrote a totally long post about Zhu Zhu pets and it disappeared when I put in the pics with the captions.

    Since I didn’t want to go thru all the permanent fix thingee you’re talking about, I took out the captions and just made the pics normal img src and it worked!

    Yay! Bless you indeed!

  • Pingback: Missing content in long Wordpress posts

  • Jason

    Hi

    Iam getting the same blank line issue for large posts. ie. 20,000 words Word doc, I paste via the kitchen sink, MS Word doc icon and it normally works. Had this large post working on a previous 2.7.1 installation. I have WordPress 2.8.2

    I tried commenting the line below as per

    http://www.undermyhat.org/blog/2009/07/sudden-empty-blank-page-for-large-posts-with-wordpress/#shortcodenote

    but to no avail,still returns a blank page when u hit publish.

    Before

    $pee = preg_replace(‘/\s*?(‘ . get_shortcode_regex() . ‘)\s*/s’, ‘$1′, $pee); // don’t auto-p wrap shortcodes that stand alone

    After recomendation in above link

    //$pee = preg_replace(‘/\s*?(‘ . get_shortcode_regex() . ‘)\s*/s’, ‘$1′, $pee); // don’t auto-p wrap shortcodes that stand alone

    Also tried deleting the entire line but to no avail?

    What else can you recommend?
    Thankyou

    • http://www.undermyhat.org Abel Braaksma

      A few days after publishing this I ran into other problems with regular expressions and crashing PHP. Just out of thin air I got some idea about looking for other PCRE directives. It turned out that PHP.INI has a setting for maximum backtrack limit which is absurdly low: 100,000 (seems high, but moderately complex regular expressions on 20K posts will more often then not reach that limit).

      The solution then is simple: increase this amount. Mine is currently set to 500,000 and I did not have anymore problems since (not really: I have loads, but not on this subject). Let me know if this works for you.

    • Jason

      Hi AB

      thanks for replying.

      1 – I have had a look in the installed subdirectory i placed wordpress 2.8 into and also in the root directory. Where is php.ini? other sites talk of inventing one yourself in notepad. If so, can you advise where do i put it and what sample base code should i place in it? maybe you have something i can directly cut and paste that includes this backtrack limit you speak of?

      2 – Looking at my first comment above, did i follow your instructions exactly re. commenting out the line with “//” in front of $pee = preg_replace(’/\s… ? if not please say and I will change something else.

      Sorry for my lack of understanding, thanks for your help

      • http://www.undermyhat.org Abel Braaksma

        Instead of “//” it should be “#”, which is the default single line comment delimiter in PHP. EDIT: either works with PHP.

        The PHP.INI is in the directory where you installed PHP (usually, it is located there). By default this is c:\program files\PHP or c:\program files\PHP5. You can also search for it, of course ;-) . Here’s some more info: http://articles.techrepublic.com.com/5100-10878_11-5268948.html

  • http://iamunr.com Paul

    Brilliant.
    Thanks alot for this fix, I had about 60 shortcodes for an easily-editable client page, and it kept erasing. I was freaking out.

    Your solution works like a charm, I appreciate you sharing it with everyone.

Get Adobe Flash player