multithreading - How to guarantee the order of function calls in PHP? -
i want implement php service 2 c# applications involved, each application reads output of previous application , generates output. wondering if can implemented line line, rather requiring threads or other asynchronous mechanism.
users can upload text file in this webpage, leads uploadfile.php
, written follows:
<?php copy($_files["file"]["tmp_name"], "uploads/" . $_files["file"]["name"]); $n1 = "uploads/" . $_files["file"]["name"]; echo "uploaded: " . $n1 . "<br>"; exec("mono c1.exe $n1"); echo "after running c1.exe"; $n2 ="uploads/c1_" . $_files["file"]["name"]; exec("mono c2.exe $n2"); echo "after running c2.exe"; ?>
assume user uploads test.txt
in webpage, c1.exe
uses content of test.txt
, generates c1_test.txt
, c2.exe
uses content of c1_test.txt
, generates c2_test.txt
.
my tests (by 1 user) show current uploadfile.php
can perform task step step.
but don't know if right implementation web service can launched many users.
could help?
edit 1: if order of execution can respected, concern whether user has wait until tasks of previous users have finished? in case when c1.exe
or c2.exe
takes several minutes run, waiting without feedback annoying.
so current approach allows several users run tasks simultaneously (but in order each user)? otherwise, have implement multi-threading myself?
you can work uniqueid :
<?php $name = uniqid(); copy($_files["file"]["tmp_name"], "uploads/" . $name); $n1 = "uploads/" . $name; echo "uploaded: " . $n1 . "<br>"; exec("mono c1.exe $n1"); echo "after running c1.exe"; $n2 ="uploads/c1_" . $name; exec("mono c2.exe $n2"); echo "after running c2.exe"; ?>
Comments
Post a Comment