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 6965419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:03:33+00:00 2026-05-27T16:03:33+00:00

I need to run a second php file in the background. The problem is

  • 0

I need to run a second php file in the background. The problem is that this file needs to only run 20 seconds after the current file has completed. I have used exec(“php test_script.php”) to run the file but I cant get it to wait. If I use sleep() if halts my current script.

To be a bit more specific. I am uploading a file to a remote server. I then need to wait approximately 20 seconds after completing the upload to check the server for a response. In the meantime I would like to carry on with the current file. The second file will do what is needed in the background. At the moment I have to wait then run the second file.

  • 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-05-27T16:03:33+00:00Added an answer on May 27, 2026 at 4:03 pm

    The simplest solution to this can be found here. Basically, execute your script like this:

    exec('test_script.php >/tmp/output.txt &');
    

    Notice the ampersand (‘&’) at the end, this will make the command run in the background! You can delay the script by 20 seconds by adding the sleep in test_script.php.

    Your other options are to trigger the second script either via Javascript (AJAX) from client side; or have a process running in the background (or regularly via cron job) which is checking some kind of common data (e.g. database) for requests, and which will get active if such a request needs to be processed.

    JavaScript is not an option if the script has to run, since the user could decide to navigate away from your page, or not be executing JavaScript, or be malicious and decide just not do execute that particular JavaScript.

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

Sidebar

Related Questions

I have one PHP script that has to start a second script in the
I'm working on an online PHP application that has a need for delayed PHP
I would like run a PHP script that runs every second to update a
i need run code that will create a database and populate tables. i am
I need to run a JavaScript function onLoad(), but only do it if the
I need to run an equipment audit and to do that I need to
I need to run multiple instances of a C program in VxWorks (VxWorks has
I need to run 8-10 instances of my application on IIS 6.0 that are
I have a php file that runs as a cron job. That file gets
I need to call two stored procedures in sequence via ODBC in PHP: #run

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.