daneth1712 Posted January 26, 2010 Share Posted January 26, 2010 Hi Guys, I really need some help with this.... I am going to try and keep this as simple as possible; otherwise I will probably just confuse myself… I have a user, that has apache/php installed on their local machine, and a web server running wamp on a win32 system. What I am attempting to do is send an update of files from the webserver to their local machine via an ftp transfer. The transfer works perfectly, up until the 6th attempt, which it just goes dead. Snippet of the code below; User would click on a link, with ?update=1 at the end, this gets sent to the webserver where the following code is waiting; $update=$_GET['update']; if($update=="1"){ $f1="test1/text1.txt"; $f2="test1/ text2.txt"; $f3="test1/ text3.txt"; $f4="test1/text4.txt"; $f5=""; $f6=""; $f7=""; $f8=""; $f9=""; $f10=""; $f11=""; $f12=""; $f13=""; $f14=""; $f15=""; header("location:http://localhost:80/ftptest.php?ftps=ipaddressofserver&un=username&pw=password&fn1=$f1&fn2=$f2&fn3=$f3&fn4=$f4&fn5=$f5&fn6=$f6&fn7=$f7&fn8=$f8&fn9=$f9&fn10=$f10&fn11=$f11&fn12=$f12&fn13=$f13&fn14=$f14&fn15=$f15&vsn=1"); exit; } Once it has found the name of the files I wish to send, it will connect to a page of their local machine, which is below; $server=$_GET['ftps']; $username=$_GET['un']; $password = $_GET['pw']; $number=$_GET['vsn']; $conn_id = ftp_connect($server); sleep(1); $login_result=@ftp_login($conn_id,$username,$password); sleep(1); //update 1 if($number=="1"){ if($login_result!="1"){ header("location:http://www.example.com/fn.php?update=1"); } elseif($login_result=="1"){ $f= $_GET['fn1']; $f2= $_GET['fn2']; $f3= $_GET['fn3']; $f4= $_GET['fn4']; $f5= $_GET['fn5']; $f6= $_GET['fn6']; $f7= $_GET['fn7']; $f8= $_GET['fn8']; $f9= $_GET['fn9']; $f10= $_GET['fn10']; $f11= $_GET['fn11']; $f12= $_GET['fn12']; $f13= $_GET['fn13']; $f14= $_GET['fn14']; $f15= $_GET['fn15']; if($f!=""){ $exp = explode("/",$f); $ex=$exp[0]; $dir = $_SERVER['DOCUMENT_ROOT']."/$ex"; if (!is_dir($dir)){ mkdir($dir,0777); } $local_file = $_SERVER['DOCUMENT_ROOT']."/$f"; $server_file = "$f"; ftp_get($conn_id, $local_file, $server_file, FTP_BINARY); } if($f2!=""){ $local_file2 = $_SERVER['DOCUMENT_ROOT']."/$f2"; $server_file2 = "$f2"; ftp_get($conn_id, $local_file2, $server_file2, FTP_BINARY); } if($f3!=""){ $local_file3 = $_SERVER['DOCUMENT_ROOT']."/$f3"; $server_file3 = "$f3"; ftp_get($conn_id, $local_file3, $server_file3, FTP_BINARY); } if($f4!=""){ $local_file4 = $_SERVER['DOCUMENT_ROOT']."/$f4"; $server_file4 = "$f4"; ftp_get($conn_id, $local_file4, $server_file4, FTP_BINARY); } if($f5!=""){ $local_file5 = $_SERVER['DOCUMENT_ROOT']."/$f5"; $server_file5 = "$f5"; ftp_get($conn_id, $local_file5, $server_file5, FTP_BINARY); } if($f6!=""){ $local_file6 = $_SERVER['DOCUMENT_ROOT']."/$f6"; $server_file6 = "$f6"; ftp_get($conn_id, $local_file6, $server_file6, FTP_BINARY); } if($f7!=""){ $local_file7 = $_SERVER['DOCUMENT_ROOT']."/$f7"; $server_file7 = "$f7"; ftp_get($conn_id, $local_file7, $server_file7, FTP_BINARY); } if($f8!=""){ $local_file8 = $_SERVER['DOCUMENT_ROOT']."/$f8"; $server_file8 = "$f8"; ftp_get($conn_id, $local_file8, $server_file8, FTP_BINARY); } if($f9!=""){ $local_file9 = $_SERVER['DOCUMENT_ROOT']."/$f9"; $server_file9 = "$f9"; ftp_get($conn_id, $local_file9, $server_file9, FTP_BINARY); } if($f10!=""){ $local_file10 = $_SERVER['DOCUMENT_ROOT']."/$f10"; $server_file10 = "$f10"; ftp_get($conn_id, $local_file10, $server_file10, FTP_BINARY); } if($f11!=""){ $local_file11 = $_SERVER['DOCUMENT_ROOT']."/$f11"; $server_file11 = "$f11"; ftp_get($conn_id, $local_file11, $server_file11, FTP_BINARY); } if($f12!=""){ $local_file12 = $_SERVER['DOCUMENT_ROOT']."/$f12"; $server_file12 = "$f12"; ftp_get($conn_id, $local_file12, $server_file12, FTP_BINARY); } if($f13!=""){ $local_file13 = $_SERVER['DOCUMENT_ROOT']."/$f13"; $server_file13 = "$f13"; ftp_get($conn_id, $local_file13, $server_file13, FTP_BINARY); } if($f14!=""){ $local_file14 = $_SERVER['DOCUMENT_ROOT']."/$f14"; $server_file14 = "$f14"; ftp_get($conn_id, $local_file14, $server_file14, FTP_BINARY); } if($f15!=""){ $local_file15 = $_SERVER['DOCUMENT_ROOT']."/$f15"; $server_file15 = "$f15"; ftp_get($conn_id, $local_file15, $server_file15, FTP_BINARY); } ftp_close($conn_id); if(!file_exists($local_file)){ header("location:http://www.example.com/fn.php?update=1"); } else{ header("location:http://www.example.com/fn.php?update=2"); } } } If this completes, it gets sent back to the page where it will look if there is another load of files to retrieve and will start the process again. This works perfectly up until the 6th attempt. The first 5 perform all the file transfers in about 20 seconds. I have increased the max_execution_time on the webserver, and on the users local machine to 600 seconds, I have increased the max_input_time on both to 180, and even tried to select ignore_user_abort = On. All with no change. At the end I just get a http error - 'This program cannot display the webpage.' I could very easily sit and try to edit every setting on both servers again and again until something changes, but I don’t have enough knowledge to just play with the settings and I know I will mess something else up in the process. Something is stopping this after the 5th attempt everytime, any help that can be offered will be extremely appreciated. I need it to perform about 20-25 transfers… if possible Thanks for taking the time to read this. If you need any additional info, please just say and will try my best to get it. Thanks in advance for any help! Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/ Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 Perhaps its not PHP but Apache's KeepAliveTimeout and the browsers timeout that needs increasing. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001878 Share on other sites More sharing options...
daneth1712 Posted January 26, 2010 Author Share Posted January 26, 2010 It probably is something like that... on the local system (users) the httpd.conf file has the following settings... PidFile logs/httpd.pid Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 15 <IfModule mpm_winnt.c> ThreadsPerChild 4 MaxRequestsPerChild 0 </IfModule> On the site server file for httpd.conf I cant find these settings.... Got to be honest, I dont know where the problem is, it could be the ftp server (which I doubt though) the local setup or the server setup... could be php or apache on either. Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001884 Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 It is probably the browser. Do a google for increasing the timeout. MS has directions to change registry settings for IE and FF is in the config, network.http.connect.timeout HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001897 Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 Just a thought. Try to send output after each file send and then flush the buffer. echo "File::$f has been transfered!<br>"; echo str_repeat(" \n", 600);// and maybe a lot of nothing that the browser will ignore just to fill its cache. flush(); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001901 Share on other sites More sharing options...
daneth1712 Posted January 26, 2010 Author Share Posted January 26, 2010 I had nearly decided to scrap this method and work on a script that uses file_get_contents, fopen and fputs. Until I realised that I need to transfer images too, which wont transfer this way as they come out corrupted at the end. :'( Thanks teamatomic so you are suggesting I add str_repeat(" \n", 600); flush() after each ftp_get($conn_id, $local_file, $server_file, FTP_BINARY); from my original post? Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001910 Share on other sites More sharing options...
daneth1712 Posted January 26, 2010 Author Share Posted January 26, 2010 ok using a flush just returns an header already used error. I also noticed I forgot to add exit; on the headers on one of the pages, but that made no difference either.... could this have anything to do with output_buffering ?? I am just clutching at straws here.... Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1001970 Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 Have not used staged buffering for a while but this works for($i=0;$i<50;$i++) { ob_start(); echo "$i<br>"; flush(); ob_end_flush(); sleep(1); } a benefit is you can increase the count in for and see when your script maxes out. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002027 Share on other sites More sharing options...
daneth1712 Posted January 26, 2010 Author Share Posted January 26, 2010 sorry to sound like a n00b, but where would i place this in my code? I just rewrote a script that used file_get_contents, fopen, fputs for all the files (eventually worked out how to transfer images without corrupting them) and it ended up doing exactly the same thing. Crashed out after 5 transfers, this time it just gives me a blank page, no errors at all. Doesnt appear to be a time execution problem as this new script completes also fairly quickly, just again after the 5th reconnect. Nearly jumped out the window as I spent a few hours rewriting that script to now have 2 scripts that work, but fail at the same place. So once I can either implement this buffering (and pray it works) to either script I will be a happy man. Otherwise need to work out what else could be causing this problem. If anyone else has any insight into this I would welcome any suggestiions, I will try anything at this stage. :'( Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002123 Share on other sites More sharing options...
daneth1712 Posted January 27, 2010 Author Share Posted January 27, 2010 Ok after some investigation into the apache error logs, I have found that the local PC (where the files are being sent too) has something called 'EACCELERATOR' installed. I am afraid I dont know much about this, but if anyone can give some pointers on ways in which I can alter the settings, or better still, remove this feature, I would really appreciate any help and assistance Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002146 Share on other sites More sharing options...
teamatomic Posted January 27, 2010 Share Posted January 27, 2010 In each of your if's if($f2!=""){ $local_file2 = $_SERVER['DOCUMENT_ROOT']."/$f2"; $server_file2 = "$f2"; ftp_get($conn_id, $local_file2, $server_file2, FTP_BINARY); //goes here to give individual output to the browser from each file transfer to stop browser timeout } Next post:: Eaccelerator. If it is on the client machine it is related to anti-virus/firewall protection but it is itself considered to be a bad actor and should probably be removed. If Eaccelerator is on the server it is a byte compiled cache type accelerator for PHP. Not used much anymore due to the popularity of the Zend-optimizer. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002155 Share on other sites More sharing options...
daneth1712 Posted January 27, 2010 Author Share Posted January 27, 2010 ok well i removed Eaccelerator, and that did nothing I tried to increased the 'ThreadsPerChild' in the apache httpd.conf file from 4 to 10, changed nothing.... I also removed the following from the httpd.conf file to see if this would make a difference, with no luck... BrowserMatch "Mozilla/2" keepalive BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 BrowserMatch "RealPlayer 4\.0" force-response-1.0 BrowserMatch "Java/1\.0" force-response-1.0 BrowserMatch "JDK/1\.0" force-response-1.0 BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully BrowserMatch "^WebDrive" redirect-carefully BrowserMatch "^WebDAVFS/1.[012]" redirect-carefully BrowserMatch "^gnome-vfs" redirect-carefully Lastly i tried your flush code, added it after every file transfer, however, it doesnt move past the first file. it now hangs for 60 seconds and i get the following result. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 1 2 3 4 5 6 Fatal error: Maximum execution time of 60 seconds exceeded in E:\xampp\htdocs\ftptest.php on line 66 Line 66 is the closing bracket in the second file for for($i=0;$i<50;$i++) { ob_start(); echo "$i<br>"; flush(); ob_end_flush(); sleep(1); }//this is line 66 Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002178 Share on other sites More sharing options...
teamatomic Posted January 27, 2010 Share Posted January 27, 2010 Ha-ha-ha-ha. You just blew away your hard drive! when you reboot its dead.... Just kidding. That was so you could see how it works. All you want to use is this ob_start(); echo "File $fx is downloaded"; flush(); ob_end_flush(); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002188 Share on other sites More sharing options...
daneth1712 Posted January 27, 2010 Author Share Posted January 27, 2010 Ok... thanks for that, but now I am getting a header error after the first transfer. Warning: Cannot modify header information - headers already sent in - which then refers to the local page (users system) refers to: header("location:http://www.example.com/fn.php?update=2"); I dont have much hair left, but am pulling what is left out... :'( I really appreciate your help! Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002331 Share on other sites More sharing options...
daneth1712 Posted January 27, 2010 Author Share Posted January 27, 2010 Ok I have tried a few more things, firstly I removed all the 'echos' within the flush, - no changes. I have added ob_start(); before every header, and added ob_flush();ob_end_flush(); after every header - no changes. I have also added <?php ob_start(); ?> at the top of the script and <?php ob_flush(); ?> to the bottom of the script... no change. There is no html code in this page, and I have removed every 'white space' from the script. There were none before or after the <?php tags anyway, but I went through every line of code in the page (about 1800 line) and removed every 'blank line' from it... still no change. I have added 'output_buffering = 4096' to the php.ini file - still nothing.... I honestly dont know what else to try.... Plus, this is just to get more than one transfer complete, before this was failing after 5 transfers, I dont even know if this is going to fix the original problem. :'( Link to comment https://forums.phpfreaks.com/topic/189849-ftp-_get-transfer-problems/#findComment-1002391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.