0

The server has various modules loading running and exiting within a session, until output to the client. My class is a plugin to a popular helpdesk system and I do not have access to modify other system files to enable ob_start().

  • Module #1
  • Module #2
  • Module #3
  • Module #4
  • Module #5 <- my class include_once here

My class needs the HTML that has accumulated by the previous modules, which will later be sent to the client.

ob_start() is not very useful in my situation since I would have to go and modify some module up the chain and add ob_start(); before it begins. We have to bear in mind that I can only work within my module

conanDrum
  • 215
  • 2
  • 7
  • You want [output buffering](https://www.php.net/manual/en/function.ob-start.php), see the examples in the manual. Also read: [What is output buffering?](https://stackoverflow.com/questions/2832010/what-is-output-buffering). – Markus AO Jul 21 '20 at 16:19
  • 1
    Does this answer your question? [What is output buffering?](https://stackoverflow.com/questions/2832010/what-is-output-buffering) – Markus AO Jul 21 '20 at 16:20
  • Not very useful in my situation since I would have to go and modify some module up the chain and add ob_start(); before it begins. We have to bear in mind that I can only work within my module. – conanDrum Jul 21 '20 at 16:47
  • Presuming the other modules don't fiddle with the output buffer, can't you just turn output buffering on at the source (= whatever that's calling all those modules)? Or, are you saying you have no control over anything except your own module? *I see you updated the question to say just that.* In that case, this question isn't a duplicate, and could be reopened. – Markus AO Jul 21 '20 at 16:52
  • In other words, this isn't running on your own server -- but instead you're providing a module that others will be using with their own server and installation of the main app, and therefore you have no control? – Markus AO Jul 21 '20 at 16:53
  • mod please reopen – conanDrum Jul 21 '20 at 16:54
  • It's in the review queue after your edit. If there's nothing you can do in PHP "upstream" from your module, or in the environment, and if the helpdesk app provides no means to access HTML from other modules, I'm afraid there's nothing to be done. You could always name the helpdesk app in your Q, someone might have a specific solution for that platform. – Markus AO Jul 21 '20 at 17:13
  • @MarkusAO thx The question should remain generic I think – conanDrum Jul 21 '20 at 17:18

1 Answers1

1

I think you would be interested in "output buffering" here is a link to PHP's documentation on the matter.


    // Start buffering the output
    ob_start();

    //... do a bunch of stuff, which will generate output
    // require/include any additional scripts too

    /**

       $output will contain all content which was outputted
       
    */
    $output = ob_get_clean();

    echo $output;// send the content to stdout... to the browser.


rexfordkelly
  • 1,623
  • 10
  • 15
  • Not very useful in my situation since I would have to go and modify some module up the chain and add ob_start(); before it begins. We have to bear in mind that I can only work within my module. – conanDrum Jul 21 '20 at 16:48
  • So you want to capture content, already sent to the browser, prior to your module running? – rexfordkelly Jul 21 '20 at 18:42
  • I would not recommend doing this, unless your module will only ever run on your projects, as it would be very intrusive. Assuming modules are loaded prior to being used, such as the case with composer, you could hijack the entire request, by starting the output buffering when your module is loaded... It would not effect the functionality of other modules, but may change the output behavior of the request... – rexfordkelly Jul 21 '20 at 18:52
  • What is the help system, you are using? – rexfordkelly Jul 21 '20 at 18:59
  • The system is osTicket. my module is running inside a sent signal/event. I cannot even buffer the output from in here. The only option that tested and works is if I buffer from a system file prior to my signal sent (event triggered). So this is impossible. I have moved to a client side solution. – conanDrum Jul 21 '20 at 19:45
  • 1
    I looked at osTicket's source, and I may be mistaken, I've not installed the source or tested it, but if your module, is bootstrapped along with the rest of the system, you can start output buffering in your plugin's bootstrap function... And then capture the output, in your module and process/inspect it as you please, you will just need to ensure you eventually dump it to the browser. – rexfordkelly Jul 21 '20 at 20:56
  • You are correct. However, I am even deeper than bootstrap into what is called a signal. In the asynchronous function of a signal I cannot start buffering. I tried. I am already off to JQuery for the job. Thanks for looking into this my friend. – conanDrum Jul 22 '20 at 22:36
  • @conanDrum, np! – rexfordkelly Jul 22 '20 at 23:26