-1

I'm trying to execute a Python script from a Php one. After trying a lot of things found on the internet, I'm still struggling with this problem : My php does not wait my python script to finish.

Indeed, It blocks when I have to import a loud class (called NeuralNetwork) in my python code.

I'd like to find a way to make my php wait the end of my python script execution.

Thank you ! (PS: sorry in advance if my english is bad)

Imports in my python file (NeuralNetworkFinal.py):

    from ControlerRn import Controler_rn
    from controler import controler
    import sys
    from NeuralNetwork import NeuralNetwork

The way I run it in my php file (formulaire.php) :

<?php
    $variableNR = 'py C:\Users\cefyo\Desktop\2018-l3al1v2\branches\NeuralNetworkFinal.py ';

    $command = escapeshellcmd($variableNR);
    $outputNR = shell_exec($command);
    echo $outputNR;

?>

I already tried to use :

< /dev/null 2>&1 &

and

   set_time_limit(0);

in my Php script but nothing happens.

When I print something between each import, theyare displayed in my $output until the line

 from NeuralNetwork import NeuralNetwork
4
  • how do you execute your php script? Commented Apr 20, 2019 at 23:44
  • by clicking a button sir Commented Apr 21, 2019 at 8:29
  • Did the duplicate question help? Commented Apr 21, 2019 at 14:20
  • Not really, we dont have the same issue. I'm still working it and I'll share if find a solution. Commented Apr 21, 2019 at 18:04

1 Answer 1

0

I'm not sure, this answer might look a bit tricky but...

<?php
$variableNR = 'py C:\Users\cefyo\Desktop\2018-l3al1v2\branches\NeuralNetworkFinal.py ';

$command = escapeshellcmd($variableNR);
$outputNR = shell_exec($command);
while(outputNR == null){ // idk if the default value is null check that please
    //do nothing
}
// echo should happen only after 'while' condition changed 
echo $outputNR;
?>
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work but that was well thought, thank you for your answer Marco !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.