Re: [PHP] how to include() N lines?

2003-09-03 Thread John W. Holmes
[EMAIL PROTECTED] wrote:

This really begs the question of WTF you have a 10,000+ line file that
you only need a couple lines from... seems like your logic is screwy.
every time my script is executed a line is added to a given image.
right now every image is saved as new file because it needs to remain
accessible in it's current state. at the moment there are only 200+
entries and the present image size is about 20 kb. but if i someday get
10'000 hits this would mean 200 mb of used disc space. (see
www.ipdraw.org)
therefore i thought it would be a more adequate way to write each
imageline() line into one text file and then as an archived entry is
requested generate the image by only including line 1 - $request_no.
since i already save a file containing some vars for each visitor maybe
something like this could be a possible solution:
$i = 1;
while ($i <= $request_no) {
 $filename = "entry-" . $i . ".php";
 include($filename); // contains $image, $ip and $color
 imageline($image, $ip[0], $ip[1], $ip[2], $ip[3], $color);
 $i++;
}
This is really begging for a database. Why not store $ip one through 
four, the color, and the datetime in a table. Then you could easily pull 
data from any dates or days or months or whatever, and just loop through 
the results calling imageline() each time...

Or, just put the IP addresses and color (and maybe date) into a csv 
file. Just fopen() the file and use fgetcsv() to get a line at a time 
and call imageline() for each line.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] how to include() N lines?

2003-09-03 Thread 457945
Am 03.09.2003 um 1:34 Uhr schrieb Chris W. Parker:
> Another option would be to tweak the logic so that it's not so bloated.

Am 03.09.03 um 01:38 Uhr schrieb John W. Holmes:
> This really begs the question of WTF you have a 10,000+ line file that
> you only need a couple lines from... seems like your logic is screwy.

every time my script is executed a line is added to a given image.
right now every image is saved as new file because it needs to remain
accessible in it's current state. at the moment there are only 200+
entries and the present image size is about 20 kb. but if i someday get
10'000 hits this would mean 200 mb of used disc space. (see
www.ipdraw.org)

therefore i thought it would be a more adequate way to write each
imageline() line into one text file and then as an archived entry is
requested generate the image by only including line 1 - $request_no.

since i already save a file containing some vars for each visitor maybe
something like this could be a possible solution:

$i = 1;
while ($i <= $request_no) {
 $filename = "entry-" . $i . ".php";
 include($filename); // contains $image, $ip and $color
 imageline($image, $ip[0], $ip[1], $ip[2], $ip[3], $color);
 $i++;
}

but as $request_no may potentially be 10'000 or higher i thought
including that much files could cause an unneeded slow down of the
whole thing.

maybe you know of a less screwy-logic method to do this (in a fast way).

thanks for your help!
philipp


/cut/
> image.php
>  header("Content-type: image/png");
> $image = imagecreate(510, 510);
> $color = ImageColorAllocate($image, 0, 0, 0);
>
> include("database.php");
>
> ImagePNG($image, '', 95);
> imagedestroy($image);
> ?>
>
> database.php
>  imageline($image, 420, 468, 308, 372, $color);
> imageline($image, 132, 154, 146, 144, $color);
> imageline($image, 420, 318, 440, 180, $color);
> imageline($image, 418, 474, 476, 320, $color);
> imageline($image, 418, 474, 476, 324, $color);
> [...]
> ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to include() N lines?

2003-09-02 Thread John W. Holmes
[EMAIL PROTECTED] wrote:
thanks for your answers! i'm not quite sure if i made my point clear. this
is my problem:
image.php

include("database.php");

ImagePNG($image, '', 95);
imagedestroy($image);
?>
database.php

instead of including the whole database.php i need to include only a given
number of lines, always starting with the first one.
because database.php contains 10'000+ lines and therefore also the number of
lines to include may be pretty high i don't know if importing the lines into
a variable is a good idea.
This really begs the question of WTF you have a 10,000+ line file that 
you only need a couple lines from... seems like your logic is screwy.

Anyhow, you have two solutions, each of which have been presented to you 
already. Either fopen() the file and read the lines you need, then 
eval() them, or copy the lines you need to another file and include that.

Like Chris mentioned, if you must keep your program running this way, 
using a filesystem call to copy X lines to a new file may be your 
fastest method.

Hate to repeat what's already been said, but those are your options. 
Post back with specific questions when/if one of these do not work for you.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] how to include() N lines?

2003-09-02 Thread Chris W. Parker
[EMAIL PROTECTED] 
on Tuesday, September 02, 2003 4:28 PM said:

> instead of including the whole database.php i need to include only a
> given number of lines, always starting with the first one.

I don't think you're going to be able to do this in the way that you
want (I've been wrong before).

I think your only option is to somehow rip the lines that you want into
another file before you do the include.

You could try using the the file system to copy only certain lines to
another temporary file and then include that temp file instead of the
whole thing.

Another option would be to tweak the logic so that it's not so bloated.


Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to include() N lines?

2003-09-02 Thread 457945
thanks for your answers! i'm not quite sure if i made my point clear. this
is my problem:

image.php



database.php


instead of including the whole database.php i need to include only a given
number of lines, always starting with the first one.

because database.php contains 10'000+ lines and therefore also the number of
lines to include may be pretty high i don't know if importing the lines into
a variable is a good idea.

any suggestions?


thanks a lot for your effort

philipp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to include() N lines?

2003-09-02 Thread Matt Matijevich
[snip]
i need to include() only a given amount of lines (the first 10 for
example)
instead of a whole file.
[/snip]


I have never tried it, but I think you could open up the file you want
to include, import n lines into a variable, then use the eval function
to turn that variable into php code.

Somebody correct me if I am wrong.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] how to include() N lines?

2003-09-02 Thread Chris W. Parker
[EMAIL PROTECTED] 
on Tuesday, September 02, 2003 3:04 PM said:

> i need to include() only a given amount of lines (the first 10 for
> example) instead of a whole file.
> 
> does someone know how this has to be done?

Yes. Remove those first ten lines (assuming they are removable) from the
original file you had them in and then include them in the old file with
include_once().

Then in the file you want to only include the ten lines just include the
smaller file.


Example: (I'm changing your 10 line requirement to 2 lines.)

Original.php:

Line 1
Line 2
Line 3
Line 4
Line 5

Take out Line 1 and Line 2 and put them in 2lines.php.

2Lines.php:

Line 1
Line 2

Then Original.php becomes this:

include_once "2Lines.php";
Line 3
Line 4
Line 5

Then in your other file that you need the 2 lines you can do just this:

NewFile.php:

include_once "2Lines.php";



HTH!
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php