Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:34:34+00:00 2026-06-07T02:34:34+00:00

BACKGROUND: Right now, in our company we have a PHP based app to automate

  • 0

BACKGROUND:

Right now, in our company we have a PHP based app to automate our report building. It works like this:

  1. A webpage with a form generates a ini file with some configurations that is saved localy
  2. a PHP CLI script accepts the ini file generated on step 1 and based on it, creates a directory with documents whose data is fetched from the internet. (takes between 5 and 10 minutes to complete)
  3. Another web form explores the content of the folder, does some validation and shows the contents of the directory as a preview.

Between any of those steps, user input is needed and sometimes the user needs to interrupt the script 2 to correct some of the ini values.


PROBLEM:

We want to run the cli script in the web browser, so that after the user clicks a “build” button, the ini file (or an array) is generated and automatically passed to the second script. But the idea is to have that script run independently (simulating another “thread”), verbosing everything it is doing along the way in order to let the user interrupt if he needs to. Something like running the script in the command line, in which each step is verbosed.


We though using AJAX, but it waits for the server to complete its answer before printing anything in the web browser.
An iFrame doesn’t work also since we can’t manipulate its src attributes and contents with javascript.

So, how can we “simulate” a command shell output? any tip n the right direction would be very appreciated.

NOTE: The script will be always used in “localhost”, no need for remote access!


SOLUTION

I ended up doing something even easier, based on the sugestions:

  • Dumped the contents of the form ($_POST) to a session var $_SESSION[‘FORM’].
  • Created a $_SESSION[form-complete] flag that would be set to true when user clicked the “build” button.
  • If the $_SESSION[form-complete] was true, the server would show an iframe pointing to the “CLI SCRIPT” whose arguments were the previously dumped session variables.
  • The CLI Script also has ob_implicit_flush(true); ob_end_flush(); so that the output won’t be cached.
  • At the end of the script the $_SESSION variable is clean and the session destroyed
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:34:35+00:00Added an answer on June 7, 2026 at 2:34 am

    An iFrame doesn’t work also since we can’t manipulate its src attributes and contents with javascript.

    You can, provided that the iframe resides on the same host as the parents pages (e.g. localhost). AJAX naturally doesn’t support cross-domain requests either, so if you have AJAX working, iframes will follow too.

    Your easiest bet will be to pipe the output to a temporary file and then have your ‘separate thread’ be an iframe/AJAX calls that retrieves the output. If it’s running on localhost, then bandwidth optimisations for this would be a bit pointless (unless the log gets really long).


    A little example:

    Suppose we want to run ./long_script. This is how we can do it.

    1. system('./long_script > /tmp/file 2>&1 &'); (pipe all output to /tmp/file, then run it in the background)

    2. Make a PHP script that does something like this (you’ll need a secure way of getting the filename, preferably a session variable, or a sanitized $_GET variable):

      <pre><?php echo file_get_contents('/tmp/file'); ?></pre><script>setTimeout("window.location.reload()", 1000);</script>

    3. Put that PHP script in an iframe. The Javascript will cause an auto-reload every 1s.


    Alternative:

    You can use popen to have a process handle, fread then flush the data (set ob_implicit_flush(true)) to the browser (so it doesn’t wait to get all the output from the process, and push it all at once).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm building a project management app in rails, here is some background
Right now I'm building a project management app in rails, here is some background
How to add a background theme and/or background wallpaper to my app? Right now
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Right now I am trying to change the background color of a org.eclipse.swt.widgets.Button with
Ubuntu 11.10, Python 2.6. Background: I have an existing Python app that is using
A little background: We're building a library/framework for working with scientific models. We have
Right now, the background I get is a grey. I want to change it
Background: we are a small webdevelopment company. We have 5 programmers that produce 70%
Right now my goal is to have anti-aliased text on my Labels. If my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.