Jump to content

Timing exec() execution


natasha_thomas

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.