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

  • Home
  • SEARCH
  • 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 8233747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:14:11+00:00 2026-06-07T18:14:11+00:00

I am wanting to execute a large, database intensive script, but do not need

  • 0

I am wanting to execute a large, database intensive script, but do not need to wait for the process to finish. I would simply like to call the script, let it run in the background and then redirect to another page.

EDIT:
i am working on a local Zend community server, on Windows 7.
I have access to remote linux servers where the project also resides, so i can do this on linux or windows.

i have this

public function createInstanceAction()
{
    //calls a seperate php process which creates the instance
    exec('php -f /path/to/file/createInstance.php');


    Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Instance creation process started. This may take up to a few minutes.'));
    $this->_redirect('instances/adminhtml_instances/');
    return;
}

this works perfectly, but the magento application hangs around for the process to finish. it does everything i expect, logging to file from time to time, and am happy with how its running. Now all i would like to do is have this script start, the controller action does not hang around, but instead redirects and thats that. from what I have learnt about exec(), you can do so by changing the way i call exec() above, to :

exec('php -f /path/to/file/createInstance.php > /dev/null 2>&1 &');

which i took from here

if i add “> /dev/null 2>&1 &” to the exec call, it doesnt wait around as expected, but it does not execute the script anymore. Could someone tell me why, and if so, tell me how i can get this to work please?

Could this be a permission related issue?

thanks

EDIT : Im assuming it would be an issue to have any output logged to file if i call the exec function with (/dev/null 2>&1 &) as that would cancel that. is that correct?

  • 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-07T18:14:13+00:00Added an answer on June 7, 2026 at 6:14 pm

    PHP popen

    From the docs (this should help you do other stuff, while that process is working; not sure if closing the current PHP process will kill the opened process):

    /* Add redirection so we can get stderr. */
    $handle = popen('/path/to/executable 2>&1', 'r');
    echo "'$handle'; " . gettype($handle) . "\n";
    $read = fread($handle, 2096);
    echo $read;
    pclose($handle);
    

    Solution 2:
    Trick the browser to close the connection (assuming there is a browser involved):

    ob_start();
    ?><html><!--example html body--></html><?php
    $strContents=ob_get_clean(); 
    
    header("Connection: Close");
    header("Content-encoding: none");//doesn't work without this, I don't know why:(
    
    ignore_user_abort(true);
    
    header("Content-type: text/html");
    header("Content-Length: ".strlen($strContents));
    echo $strContents;
    
    flush();
    //at this point a real browser would close the connection and finish rendering; 
    //crappy http clients like some curl implementations (and not only) would wait for the server to close the connection, then finish rendering/serving results...:(
    
    //TODO: add long running operations here, exec, or whatever you have.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting this script to print 1,2,3.. without the use of functions, just execute
I'm a newbie to PowerShell. What's wrong with my script below? It's not wanting
I would like to perform some arbitrarily expensive work on an arbitrarily large set
I have a database that has a 'plant' theme. I am wanting a script
I'm wanting a more secure way to store high scores and power ups like
I'm wanting to set the current time i my database My column is a
I need to wait for document readyness in my JavaScript, to insert a div
I am wanting to maintain a second copy of a MS SQL 2008 database
I'm wanting to create a process from a different location to where my application
Problem We have a DBA provided wrapper script that is used to execute a

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.