简体   繁体   中英

Execute shell script in the background while a page is displayed on screen to the user in php

In my application, I am running a shell script but till the script completes executing the screen is blank. I am not able to display anything on screen. I want to display the log file to the user so till the log file is generated, i want the user to see some text content on the screen.

I read previous questions posted where they say multithreading in php is not possible.

Is there a way i can do this?

These two questions might be of some help:

1> exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));

php execute a background process

2> ignore_user_abort(true)

I would use jQuery.

Call the page loading the php script from the main page.

Mainpage

  • Basic html page with a $(document).ready() loading the script.php page using jQuery.get()
  • At initial state, a div contains some text.
  • When success is called, load content in same div.

Link to jQuery.get() : http://api.jquery.com/jQuery.get/

These questions suggest it is and isn't possible, depending on whose answer your looking at; Multithreading in PHP

How can one use multi threading in PHP applications

You should take a look at; http://joseph.randomnetworks.com/2005/10/21/fake-fork-in-php/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM