fmarinheiro
fmarinheiro

Reputation: 87

concurrency and PHP scripts

I'm trying to fire a php script inside another php script. This is easy, the problem is that the first script can not wait for the second to finish. I want a fire and go mechanism.

Any help would be appreciated,

Thanks in advance.

Upvotes: 1

Views: 429

Answers (2)

RobertPitt
RobertPitt

Reputation: 57268

You would have to use exec()

On your server / Operating system add the php/bin directory to your environment variables and then execute the command like so:

<?php
    //Blah

    exec("php /path.to.file.php /dev/null");

    //Blah
?>

Upvotes: 1

Joonas Pulakka
Joonas Pulakka

Reputation: 36577

From exec documentation:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

That is, the following should work:

exec("php /path.to.file.php > /dev/null");

Upvotes: 2

Related Questions