MyBB Community Forums

Full Version: Exec() doesnt work ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have to run a php file via exec() or shell_exec() which are located inside a function of my custom plugin.

But i quickly realized that it doesnt work. Calling exec() from a non plugin .php works perfectly instead.
Is this a setting, or a security measure which cant be turned off ?

MyBB version 1.8.5.

Thanks
Can you clarify what "doesn't work" means? Does it error or just not do what you're expecting? There won't be any difference between running it in a plugin file vs anywhere else, we can't stop or control a PHP function being called, the only restriction would be if it's disabled by your host.

Also, I'd advise upgrading as soon as possible as 1.8.5 is very old.
(2021-03-17, 07:17 PM)Matt Wrote: [ -> ]Can you clarify what "doesn't work" means?

It just doesnt execute a simple "exec('whoami')" inside a plugin function at all. (seems like it skips it completely)
But it does in a normal php script.
Cant let it print any errors as well.


(2021-03-17, 07:17 PM)Matt Wrote: [ -> ]Also, I'd advise upgrading as soon as possible as 1.8.5 is very old.
Thanks for this advice.
First of all check whether exec function is...

- available/enabled:
if(function_exists('exec')) echo 'OK';

- actually processing:
if(@exec('echo ABC') == 'ABC') echo 'OK';

Try that outside of a plugin script as well - e.g. with a separate *.php file.

If not positive, then check your PHP configuration (php.ini) for the function disabled.
When there is no access to php.ini, ask your webhoster to assist.

[ExiTuS]
(2021-03-17, 08:31 PM)pafin Wrote: [ -> ]
(2021-03-17, 07:17 PM)Matt Wrote: [ -> ]Can you clarify what "doesn't work" means?

It just doesnt execute a simple "exec('whoami')" inside a plugin function at all. (seems like it skips it completely)
But it does in a normal php script.
Cant let it print any errors as well.

Can you echo something out before the exec call? Like this:

echo 'test123';
echo exec('whoami');

exec seems to need echo before it too if you're just doing whoami.

I don't think it's even possible for us to stop exec() being called in a plugin even if we wanted to, so it sounds like the plugin hook isn't running at all more than anything.
I have misspelled plugin hook names before and that has been a source of frustration when trying to figure out why my code won't work.
I'm curious about the practical use of this within a plugin.
(2021-03-18, 12:10 AM)Omar G. Wrote: [ -> ]I'm curious about the practical use of this within a plugin.

I just want a mybb hook to start a separate php process (which doesnt hang up the main thread)

(2021-03-17, 09:55 PM)[ExiTuS] Wrote: [ -> ]First of all check whether exec function is...

- available/enabled:

- actually processing:
Its enabled and is processing

But when i do something like
exec('/usr/bin/php /directory/script.php')

It wont execute the content inside the php.


(2021-03-17, 10:01 PM)Matt Wrote: [ -> ]Can you echo something out before the exec call? Like this:
echo exec('whoami');
It works fine as well
@Omar, Me, too.

(2021-03-18, 12:31 AM)pafin Wrote: [ -> ][...]
Its enabled and is processing

But when i do something like
exec('/usr/bin/php /directory/script.php')

It wont execute the content inside the php.
Ehh... struggling... it makes no sense to execute a PHP file via shell using exec() within PHP Smile
[This way you will let the PHP parser run again parsing PHP while parsing PHP]

If you want to embed different PHP files within your PHP file, try functions like "include ./script.php", "require ./script.php" or "require_once ./script.php".

(2021-03-18, 12:31 AM)pafin Wrote: [ -> ]
(2021-03-17, 10:01 PM)Matt Wrote: [ -> ]Can you echo something out before the exec call? Like this:
echo exec('whoami');
It works fine as well
exec() runs an operating system command, not other PHP files and functions.

Please let us know what is the exact command you're going to execute with exec() within your PHP file.

[ETS]
(2021-03-18, 01:09 AM)[ExiTuS] Wrote: [ -> ]If you want to embed different PHP files within your PHP file, try functions like "include ./script.php", "require ./script.php" or "require_once ./script.php".

Please let us know what is the exact command you're going to execute with exec() within your PHP file.

I just need this second php to get some data from a distant server, and i dont want the plugin function to wait until its completed.
Thats all i am trying to achive.
Pages: 1 2