Search code examples
phpprocessbackground-processpdf2swf

PHP Launch script after background process completes?


I am converting a PDF with PDF2SWF and Indexing with XPDF.. with exec.. only this requires the execution time to be really high.

Is it possible to run it as background process and then launch a script when it is done converting?


Solution

  • in general, php does not implement threads.

    But there is an ZF-class which may be suitable for you:

    http://framework.zend.com/manual/en/zendx.console.process.unix.overview.html

    ZendX_Console_Process_Unix allows developers to spawn an object as a new process, and so do multiple tasks in parallel on console environments. Through its specific nature, it is only working on nix based systems like Linux, Solaris, Mac/OSx and such. Additionally, the shmop_, pcntl_* and posix_* modules are required for this component to run. If one of the requirements is not met, it will throw an exception after instantiating the component.

    suitable example:

    class MyProcess extends ZendX_Console_Process_Unix
    {
        protected function _run()
        {
            // doing pdf and flash stuff
        }
    }
    
    $process1 = new MyProcess();
    $process1->start();
    
    while ($process1->isRunning()) {
    
        sleep(1);
    
    }
    
    echo 'Process completed';
    

    .