natasha_thomas Posted January 11, 2011 Share Posted January 11, 2011 Folks, I am running Linux Commands in PHP. I am looping through the Domain list and using the below line in my Script: exec('cp -r '.$source.' '.$destination); I am using this in a Foreach Statment, so only the last Even in the loop getting executed, because, the loop is running too fast so the Linux command does not even get initiated, only the last even in loop goes through. What i have done is, i have added a line after exec(); sleep(30); This gives enough time for Linux command to get executed, but is it efficient way to handle timing liek this? Do i need to use time_limit() or something like that? Cheers Natasha Quote Link to comment Share on other sites More sharing options...
phpchamps Posted January 11, 2011 Share Posted January 11, 2011 Hey Natasha, As you are using the exec command the third parameter of exec command is return_var which will return the status of the execture command. I think you should check for the return status and if status is true then you can continue the loop or else break it. Hope it helps. Thanks. Quote Link to comment Share on other sites More sharing options...
natasha_thomas Posted January 11, 2011 Author Share Posted January 11, 2011 Hey Natasha, As you are using the exec command the third parameter of exec command is return_var which will return the status of the execture command. I think you should check for the return status and if status is true then you can continue the loop or else break it. Hope it helps. Thanks. Very Nice Mr. Champ... So does exec() return some sort of Boolen True or false? Cheers Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 11, 2011 Share Posted January 11, 2011 Why not just use PHP to copy the files instead of exec'ing a linux command? So does exec() return some sort of Boolen True or false? http://php.net/manual/en/function.exec.php Quote Link to comment Share on other sites More sharing options...
phpchamps Posted January 12, 2011 Share Posted January 12, 2011 So does exec() return some sort of Boolen True or false? If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable. I would suggest you to use ftp commands of php to copy files to different server. http://php.net/manual/en/book.ftp.php 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.