dsepcxw181184853 2014-09-29 14:44
浏览 59
已采纳

PHP在活动页面上显示后端脚本的输出

I have a web application in PHP. One component of the application is submitting the data to a backend pipeline (also written in PHP). The pipeline is an external script, which my application calls using 'exec' php function. The pipeline is a multistep pipeline which executes several programs taking input from the program run before. I want to be able to display a message on the application page which submits to the pipeline, with completion of each step in the pipeline, such as

Step 1 completed... Now doing step 2. Step 2 completed... Now doing step 3.

and so on and so forth.

I am open to use javascript/AJAX to do this, and also any other language compatible with PHP.

Any help is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • duanguangsong2380 2014-09-29 14:50
    关注

    Well working on the assumption that you have some kind of database backing your PHP front-end and pipeline, you don't specifically need something compatible with PHP, but rather something that could interface with your database.

    Without having any further details on what you've set up/tried, etc. I can only offer an overview of the workflow I would use in this situation.

    • Front-end script is submitted and pushes the request into a processing queue.
    • User is shown a "processing, please wait" type page. This page makes a long-polling AJAX request or a Websocket connection to the front-end site to a script which polls the database for updates on the pipeline processing.
    • The pipeline scripts chain off each other and push into the database the details of their completion which are read off by the Websocket/long-polling front-end script and returned to the user via Javascript to display on the page.

    Using the database as a go-between would be the easiest and most flexible approach. You could also use other languages if you're more comfortable with them so long as they're compatible with your database used on the PHP/pipeline side.

    EDIT

    While I don't have any links to a tutorial on exactly what you want to do, there are some basics behind it that you can use to piece together your solution:

    I would start by getting your pipeline (processing) script to run in the background at interval using cron. Alternatively you could daemonize that pipeline using something like this PHP-Daemon framework so that it runs in the background. Perhaps having a cron task to check if it's running and restart it if needed.

    From there you can build a table in your database that contains status updates on the processing tasks at hand and build a PHP script that checks the status of a given task and outputs JSON data about it. This JSON data could easily be read using AJAX requests, the simplest of which would probably be jQuery's .ajax() method. This could be called at interval on the client side "status" page using a setTimeout call at the end of each "loop" to poll for status changes every X seconds. This would be the easiest implementation of what you're after, although not the best performing or optimal way to do it.

    So the general workflow here would change to this:

    • Front-end script is submitted and pushes the request into processing queue with status set to pending.
    • User is shown the processing page which pings status.php?task=12345 every X seconds.
    • Back-end daemon/cron script picks up the request and begins processing, pushing status updates into the database at interval.
    • status.php script begins to return different status information in the JSON code and it is displayed to the user.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)