[TYPO3-dev] Run script in the background, using CLI-mode

David Bruehlmeier typo3 at bruehlmeier.com
Thu Jan 19 19:38:53 CET 2006


Hi,

I am writing a script which will generate large files. Because on most 
servers, the script would be terminated after 30 seconds due to the 
standard timeout settings, I want the script to run in the background.

So when the online-script (start.php) is called, I check for the 
operating system and then call the background script accordingly. I'm on 
a windows machine, so I did get it to run on windows. However, it fails 
to run on Linux. Unfortunatly, I don't know Linux very well, so if 
someone could help me out, that would be awesome!

Thanks a lot,
Dave.



Here's the relevant code:

----- start.php -----
$args = t3lib_extMgm::extPath('partner').'cli/'.'create_report.php 
-'.$this->reportUid;

function execInBackground($args='')		{
	if (TYPO3_OS == 'WIN')		{
		@pclose(popen('start /B php.exe '.$args, 'r'));
	} else {
		@exec('./php '.$args.' > /dev/null &');
	}
}
	
----- create_report.php -----
#!/usr/bin/env php
<?php

// Defining circumstances for CLI mode:
define('TYPO3_cliMode', TRUE);

// Defining PATH_thisScript here: Must be the ABSOLUTE path of this 
script in the right context:
// This will work as long as the script is called by it's absolute path!
//
// Example from "Inside TYPO3" did not work on Windows.
// define(PATH_thisScript, $_ENV['_'] ? $_ENV['_'] : $_SERVER['_']);
define(PATH_ts, $_ENV['_'] ? $_ENV['_'] : $_SERVER['argv'][0]);

// Include configuration file:
require(dirname(PATH_ts).'/conf.php');

// Include init and template file:
require(dirname(PATH_ts).'/'.$BACK_PATH.'init.php');
require(dirname(PATH_ts).'/'.$BACK_PATH.'template.php');

// .... do the stuff ....
?>




More information about the TYPO3-dev mailing list