Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 16th, 2013, 1:14 PM   #1
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
rtrim on an array

$newfn =  rtrim($f['file'], ".gz");

gives me errors about "$f['file']" must be a string. well i have tried stuff but ran out of ideas. i know there is array_map but not sure how to tell it to take off the '.gz'.

thanks for any help
origamiguy is offline   Reply With Quote
Old Aug 16th, 2013, 2:27 PM   #2
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: rtrim on an array

once again--nevermind i found it....

$newfn =  rtrim(strval($f['file']), ".gz");
origamiguy is offline   Reply With Quote
Old Aug 16th, 2013, 3:01 PM   #3
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: rtrim on an array

quick question... how long should it take to decompress a .gz file in php. i am going on 10 mins now and the compressed size is 5655KB?
origamiguy is offline   Reply With Quote
Old Aug 16th, 2013, 3:59 PM   #4
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: rtrim on an array

hour has come and gone and still my hand written decompresser is on only the first file out of like 6 or 7.

i really need a much faster way.
origamiguy is offline   Reply With Quote
Old Aug 16th, 2013, 5:35 PM   #5
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: rtrim on an array

so that same file is STILL decompressing and it is 5 times the compressed size. when will it end. will post the code i am using in a sec for some help speeding it up.
$file_query = "SELECT FileName AS file From Filter";
	
	if($fq = mysqli_query($conn,$file_query))
	{
		while($f = mysqli_fetch_array($fq,MYSQL_ASSOC))
		{
			if(file_exists($_SERVER['DOCUMENT_ROOT'].'\NewSite\company\\' . $f['file']))
			{
				echo "company/" . $f['file'] . " was found <br>";
				if(preg_match('/\.gz$/',$f['file'], $matches))
				{
					echo "this is a .gz file!!! <br>";
					if($file = gzopen("company/" . $f['file'], 'r')){
						$newfn =  rtrim(strval($f['file']), ".gz");
						echo $newfn . "<br>";
						while(!gzeof($file)){
							while($write = gzread($file,2000)){
								file_put_contents("company\\" . $newfn, $write, FILE_APPEND | LOCK_EX);
							}
						}
						print "I guess it works....<br>";
					}else{
						echo "The file didn't open.";
					}
				}
			}
			else
			{
				echo "company/" . $f["file"] . " was NOT found <br>";
			}
		}
	}

note use the toggle plain text for a cleaner read
origamiguy is offline   Reply With Quote
Old Aug 16th, 2013, 7:01 PM   #6
The Dark
Programming Guru

 
Join Date: Jun 2005
Posts: 1,631
Rep Power: 14 The Dark will become famous soon enoughThe Dark will become famous soon enough
Re: rtrim on an array

I suspect it is because file_put_contents is opening, locking, writing, unlocking and then closing the file for each 2000 bytes.
You could try opening the file before the loop and then just writing inside the loop, like the code in the first answer here: http://stackoverflow.com/questions/1...th-gzip-in-php
The Dark is offline   Reply With Quote
Old Aug 16th, 2013, 7:35 PM   #7
origamiguy
Programmer
 
Join Date: Jan 2013
Posts: 55
Rep Power: 5 origamiguy is on a distinguished road
Re: rtrim on an array

ok changed it to how it showed. starting test now...thanks

EDIT:: I LOVE YOU SIR DARK. took less than 10s to run all 6 files instead of the hour and a half and only part way done with the first file. seriously thanks. also i only changed like 2 or 3 lines for this to work.

i say it again. love the people on here

Last edited by origamiguy; Aug 16th, 2013 at 7:47 PM.
origamiguy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing array elements and adding another value oneshot2shots PHP 1 Jul 31st, 2013 3:05 PM
I have problem with Array yuriy_777 C++ 10 Feb 11th, 2010 4:28 AM
dynamic array help quickster12 C++ 4 Nov 30th, 2007 12:52 AM
problem processing file into a char array csrocker101 C++ 1 May 9th, 2007 12:50 AM
changing size of an array Eric the Red Java 3 Apr 3rd, 2006 9:19 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC