Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function (imported from ezscriptmonitor) to launch a script in background #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions kernel/classes/ezscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,24 @@ function updateTextCodecSettings()
eZTextCodec::updateSettings( $i18nSettings );
}

/*!
\static
Execute a process in the background, should work on both Linux and Windows
From php doc:
http://no.php.net/manual/en/function.exec.php#86329
*/
static function execInBackground( $command )
{
if ( substr( php_uname(), 0, 7 ) == 'Windows' )
{
pclose( popen( 'start /B ' . $command, 'r' ) );
}
else
{
exec( $command . ' > /dev/null &' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not taking advantage of PCNTL if present instead ? The exec() call would be used as a (dirty) fallback then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm currently fighting with it :) I can't succeed in creating a subprocess in background in a php page launched in apache environment

But you're right, it would be nice to have pcntl if available, and if possible to do this

But for now, why not merging this new function right now, and improve it afterwards with pcntl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, now I understand the e-mail you sent to @bdunogier ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)
Indeed for my need to launch a process in background from ezjscore/call, I've discovered I can use ezscriptmonitor that fits my need
However the question on pcntl in apache env is still interesting, in order to improve this function and avoid the (dirty) exec.

But as said before, maybe it's worth merging now, and improve it afterwards :)
Tell me if it can't be merged for some reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for the question on "how to use pcntl in apache environment ?", the answer is there:
http://fr2.php.net/manual/en/intro.pcntl.php

Php advises to never do that...

As a result, an enhancement to this function could be to use pcntl yes, but in cli env, not in apache env

}
}

/// \privatesection
public $InitializationErrorMessage;
public $DebugMessage;
Expand Down