d.shankar Posted October 3, 2009 Share Posted October 3, 2009 Hi all ! I had this forking script with php running fine. But today i moved to a new host, but the parameter is not getting fetched. The main concept behind the code is EXEC() forking. we have 2 files parent.php and child.php. the parent.php when executed creates a file and registers the time in the file it began and forks a child process and gets exited. the child process now executes and registers its time and then exits. These things work fine but the parameter i send from the parent process is not getting feched to the child process. but the same script is running in other servers. parent.php <?php error_reporting(E_ALL); // place these two lines at the top of ini_set('display_errors', 1); // the script you are debugging //echo exec('whoami'); $book="god"; exec("child.php testing $book > /dev/null 2>&1 &"); if ($fp = fopen("log.txt", "a")) { fwrite($fp, "Parent process finished at ".date("H:i:s", time())."!\n"); fclose($fp); } ?> Child.php <?php error_reporting(E_ALL); // place these two lines at the top of ini_set('display_errors', 1); // the script you are debugging sleep(5); if ($fp = fopen("log.txt", "a")) { fwrite($fp, "Child process $argv[1] $argv[2] finished at ".date("H:i:s", time())."!\n"); fclose($fp); } ?> I am waiting... Thanks Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 Make sure your log.txt file has 777 Permissions. if log.txt is in a sub folder, the folder need to be 777 aswell. if your getting errors could post the error your recieving? Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 Thanks for replyin ProXy_ I aint getting any errors The expected result is Parent process finished at 7:03:45 Child process testing god finished at 7:03:50 FYI : testing and god are the variables i send from parent.php The result i get now is Parent process finished at 7:03:45 Child process finished at 7:03:50 The variables are not getting printed. Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 ok, i would try this then.. Parent <?php error_reporting(E_ALL); // place these two lines at the top of ini_set('display_errors', 1); // the script you are debugging //echo exec('whoami'); $book="god"; exec("child.php testing $book > /dev/null 2>&1 &"); $fp = fopen("log.txt", "a"); fwrite($fp, "Parent process finished at ".date("H:i:s", time())."!\n"); fclose($fp); ?> Child <?php error_reporting(E_ALL); // place these two lines at the top of ini_set('display_errors', 1); // the script you are debugging sleep(5); $fp = fopen("log.txt", "a"); fwrite($fp, "Child process $argv[1] $argv[2] finished at ".date("H:i:s", time())."!\n"); fclose($fp); ?> hopefully this helps. Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 did u just remove the if loop ? Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 I removed the if statement, its not a loop. Basicly your saying if $fp = "blah" then: save information.. But your not previously calling $fp to be anything at all.. therefor its not going to do anything but sit there unless your leaving code out and your calling $fp somewhere down the line to be log.txt Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 Nope. the same "space" is getting printed. Main process finished at 14:44:24! Child process finished at 14:44:29! Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 oh, i appologize, i thought it wasn't saving anything at all.. it sounds like in Child.php the variables $argv[1] $argv[2] aren't passing anything through can i see the form source? Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 form source ??? i have posted all the code Proxy. Just the 2 files !! Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 Actually i was asking where is $argv[1] $argv[2] being called from? if you notice in child.php where $argv[1] $argv[2] it prints the spaces. thats because $argv[1] $argv[2] doesn't equal anything. So i did a little research with $argv and i here is a link i'll send you to that should explain everything you need only thing i can think of is your current host doesn't have register_argc_argv enabled. you can read more about it here: http://www.php.net/manual/en/ini.core.php#ini.register-argc-argv Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 i checked the phpinfo register_argc_argv is set to ON what's happening really i dont know.. Proxy Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 ok, as i'm doing research on this Lets try this. child.php <?php $argv=$_SERVER['argv']; error_reporting(E_ALL); // place these two lines at the top of ini_set('display_errors', 1); // the script you are debugging sleep(5); if ($fp = fopen("log.txt", "a")) { fwrite($fp, "Child process $argv finished at ".date("H:i:s", time())."!\n"); fclose($fp); } ?> this is only testing but lets see what that does. Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 should i run this separately or using parent process ?? Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 that is the child.php. run the script like usual.. we need to see if argv holds anything. by using $_SERVER['argv']; We're basicly debugging but just run the script like you normally do. Also, can i get your php version? Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 proxy, it shows the same result with a space. i think arguments are not getting passed Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 ok, can i see what the results look like? on the host that the script works on. therefor i can maybe get a little bit more of an understanding. Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 3, 2009 Author Share Posted October 3, 2009 i think i am worried that the host has blocked argv accees. is that possible ?? Quote Link to comment Share on other sites More sharing options...
ProXy_ Posted October 3, 2009 Share Posted October 3, 2009 Very possible. and also it seems from research that PHP 4.3+ won't support alot of commands sent through $argv wich is why i asked your php version. and hosts can disable use of argv commands or Command line scripting period. but i won't stop i'll keep up with the research and get your answer Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 4, 2009 Author Share Posted October 4, 2009 Thanks a lot proxy , but unfortunately the research goes more weirder.. cause the PHP version is 5.2.8 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.