• Resolved reviewmylife

    (@reviewmylife)


    Hi, I’ve had a go at injecting dynamic PHP (with the mfunc/mclude tags) into a page using the a plugin. The PHP does not run on the first time the page is loaded, but does on subsequent loads. The reason is simple.

    On the first load the PHP is injected by the plugin, and WP Super Cache returns a buffer of the file contents that it had in memory. It also saves the buffer to disk for use next time. The page contents returned to the browser has the actual PHP code embedded in it as it was not interpreted.

    On the second load the cached file on disk is returned. This allows any PHP contained within this file to run.

    Is there any easy way to add an option so that WP Super Cache always returns the cached file, rather than returning the memory buffer if this is the first load of the page?

    So on load one it would save the cached page to disk and then return the cached page to the user.

    On subsequent loads it would just return the cached page.

    Hope this makes sense!

Viewing 1 replies (of 1 total)
  • Thread Starter reviewmylife

    (@reviewmylife)

    Hi, I’ve figured out a work around so thought I’d update this in case anyone else is having the same problem.

    Before injecting the mfunc/mclude code into the page using my plugin I send them though the ‘eval’ function to execute the PHP. This fixes the problem of the PHP only executing after the 1st page load. On the 2nd and subsequent loads the PHP is executed from the static cached page.

    For an example of using eval see the Exec-PHP plugin.

    p.s. Technically you could just let Exec-PHP execute the code, but as the Exec-PHP plugin has a priority of ‘1’ you’d have to give your plugin a 0 or negative priority to get the PHP into the page before Exec-PHP sees it. Probably not a good idea.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: WP Super Cache] Injecting PHP into page – problem on first load’ is closed to new replies.