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
https://forums.phpfreaks.com/topic/224057-timing-exec-execution/
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.

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.