Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Copy function slower than linux cp command when copying from remote NFS share

Tags:

linux

php

cp

I have been trying to copy an audio file from nfs share on another server. When I use PHP to copy the it takes 5.5 seconds to copy an 8 MB audio file. However when I use the cp command in the shell it takes 0.845 seconds.

Does anyone have any idea what the problem is and how to fix it?

<?php
  $result = copy('/remote/dir/remoteFile.wav’,’12345.wav');
  var_dump($returnVar);
?>
like image 582
shaun Avatar asked Nov 15 '25 00:11

shaun


1 Answers

Also, you can be certain the the PHP copy will be slower than linux cp because one uses native OS level calls, and the other is application layer which invokes the same through the web server et al. Too many layers to go through, notifications to process, protocols to adhere to etc etc.. I do not think this is exactly fixable..

Maybe instead of a copy() you could try an exec('cp ..') command which will directly try to run the linux cp command from php. Might not give you as much speed as cp from shell, but might make it a bit more faster than copy() from php. Give it a try..

like image 118
raidenace Avatar answered Nov 17 '25 20:11

raidenace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!