PHP and run 2 scripts

Posted on 2006-04-15
Last Modified: 2006-11-18
I would like to have a background script running that will run continuously but am having problems in trying to get it working, if it is possible.  Basically a user submits a form and it'll load two scripts, one background script and one foreground script.  I tried using frames to do it, with the background script in one frame and a foreground script in another frame.  But if the background script runs continuously in the first frame the second frame which contains the foreground script can never get processed.  Also the foreground script will refresh probably about every 30s or so and I am using meta tags to do it.  So how can I have a background script continuously running and also have the foreground script be processed as well?
Question by:kdavidm
    LVL 15

    Expert Comment

    Hi kdavidm,

    Not entirely sure what it is that you are trying to do.   What are these scripts actually going to be doing?  Particularly, what is the script that you want to be running continuously?  Since PHP is server side.. I'm not sure what the background script could actually be doing that would require it to be running indenfinitely.

    Author Comment

    The background script just gets updates from user interaction and communication then stores the data in a database, the foreground script reads in these updates from the database and outputs them every 30s for example.  Yes I know it isin't very efficient and yes there are better and more simpler ways to do it without using PHP, but I want to use PHP to do it.  So I would like to know if it's possible to have two scripts running, one background continuously and one foreground.
    LVL 15

    Accepted Solution

    I don't think you can really accomplish this with just PHP.  If you're wanting to retrieve client-side information continuously without the user actuall submitting something, I think you would need to use some type of Javascript (possibly an AJAX script), or even ActiveX.  Regardless of how you do it.. you can't just have a stand-alone PHP script that actually RUNS continuously and keeps retrieving client-side data.  PHP doesn't work the same way a Windows executable or service would work, for example.
    LVL 16

    Expert Comment

    PHP script ends the moment it is relivered to the client and no way to leave it running. Maybe you can use php-java integration, haven't tried it my self, but have a look at that link
    LVL 11

    Expert Comment

    Try to take a look PHP command line
    PHP-CLI (Command Line Interface), may it can work for your case.
    LVL 11

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now