Apr 7, 2010 5:16 pm
IkkeHi everybody,
While going through the code of an OS website, I noticed all the links were
replaced by defines. Everytime someone wanted to use a link, said link was
added to an included file, and echo'd in the page where the link should be.
The entire include file (links.inc) consisted of lines like the following:
define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
At first I liked the idea - if you want to change a link, you only have to
change it once, which is quite a benefit.
However, how many of these defines are allowed in PHP? I've had a quick
Google for an answer, but couldn't come up with a definitive answer.
Could somebody please tell me if there is a limit on the number of defines,
and if so, what that limit is?
Thanks in advance!
Ikke
Apr 7, 2010 5:38 pm
Jerry StuckleIkke wrote:
> Hi everybody,
>
> While going through the code of an OS website, I noticed all the links were
> replaced by defines. Everytime someone wanted to use a link, said link was
> added to an included file, and echo'd in the page where the link should be.
>
> The entire include file (links.inc) consisted of lines like the following:
> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
>
> At first I liked the idea - if you want to change a link, you only have to
> change it once, which is quite a benefit.
>
> However, how many of these defines are allowed in PHP? I've had a quick
> Google for an answer, but couldn't come up with a definitive answer.
>
> Could somebody please tell me if there is a limit on the number of defines,
> and if so, what that limit is?
>
> Thanks in advance!
>
> Ikke
>
> While going through the code of an OS website, I noticed all the links were
> replaced by defines. Everytime someone wanted to use a link, said link was
> added to an included file, and echo'd in the page where the link should be.
>
> The entire include file (links.inc) consisted of lines like the following:
> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
>
> At first I liked the idea - if you want to change a link, you only have to
> change it once, which is quite a benefit.
>
> However, how many of these defines are allowed in PHP? I've had a quick
> Google for an answer, but couldn't come up with a definitive answer.
>
> Could somebody please tell me if there is a limit on the number of defines,
> and if so, what that limit is?
>
> Thanks in advance!
>
> Ikke
More than you're likely to ever use. No hard limit, AFAIK, but you'll
run into other constraints such as memory usage.
The bigger problem will be parsing thousands of define statements which
will never be used in the current script.
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Apr 7, 2010 6:49 pm
Lars EighnerIn our last episode, <Xns9D53C42D442A7ikkehierbe@69.16.176.253>, the lovely
and talented Ikke broadcast on comp.lang.php:
> Hi everybody,
> While going through the code of an OS website, I noticed all the links were
> replaced by defines. Everytime someone wanted to use a link, said link was
> added to an included file, and echo'd in the page where the link should be.
> replaced by defines. Everytime someone wanted to use a link, said link was
> added to an included file, and echo'd in the page where the link should be.
> The entire include file (links.inc) consisted of lines like the following:
> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
> At first I liked the idea - if you want to change a link, you only have to
> change it once, which is quite a benefit.
> change it once, which is quite a benefit.
> However, how many of these defines are allowed in PHP? I've had a quick
> Google for an answer, but couldn't come up with a definitive answer.
> Google for an answer, but couldn't come up with a definitive answer.
> Could somebody please tell me if there is a limit on the number of defines,
> and if so, what that limit is?
> and if so, what that limit is?
> Thanks in advance!
There are various limits to memory and file size which are set in
the php.ini file, the most pertinent of which are the memory size and the
maximum script execution time. These might be negotiable (or not) with your
web host. Of course if it is your own machine there are hardware
limitations behind the software limits, and you cannot do anything about
that except upgrade the hardware.
You certainly can handle megabytes of defines even on a fairly stingy
service, which is more links than you will have on even a large corporate
site. There is no definitive answer, since the limit depends on software
limitations set by the server and they underlying hardware limitations.
The problems are: the processing times involved in loading huge files of
defines and the issue of how you will maintain such files. You will bump
your head hard on these issues long before you will reach the theoretical
software and hardware limits. How large a text file can your text editor
handle? How large a text file can you reasonably edit?
If you want to compete with Google, you will have to --- as a practical
matter --- use a database where you can leverage the look-up and maintenance
problems with the database's indexing abilities. Which is to say, defines
are not the way to go with huge numbers of links.
Defines might be realistic if you have a few links that are used on almost
every page --- perhaps a few dozen at most. Even on a personal site, if you
have hundreds of links, many of which are used only once, you should be
using a database, if only for ease of maintenance.
Lars Eighner <http://larseighner.com/> Warbama's Afghaninam day: 126
When you explode with newline as a delimiter you get an extra, empty element
at the end if the string ends with a newline. Use rtrim on the string first.
-1 for explode limit will be wrong if the string doesn't end with a newline.
When you explode with newline as a delimiter you get an extra, empty element
at the end if the string ends with a newline. Use rtrim on the string first.
-1 for explode limit will be wrong if the string doesn't end with a newline.
Apr 7, 2010 6:55 pm
GuestOn Wed, 07 Apr 2010 13:38:45 -0400, Jerry Stuckle
<jstucklex@attglobal.net> wrote:
>Ikke wrote:
>More than you're likely to ever use. No hard limit, AFAIK, but you'll
>run into other constraints such as memory usage.
>
>The bigger problem will be parsing thousands of define statements which
>will never be used in the current script.
>> Hi everybody,
>>
>> While going through the code of an OS website, I noticed all the links were
>> replaced by defines. Everytime someone wanted to use a link, said link was
>> added to an included file, and echo'd in the page where the link should be.
>>
>> The entire include file (links.inc) consisted of lines like the following:
>> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
>>
>> At first I liked the idea - if you want to change a link, you only have to
>> change it once, which is quite a benefit.
>>
>> However, how many of these defines are allowed in PHP? I've had a quick
>> Google for an answer, but couldn't come up with a definitive answer.
>>
>> Could somebody please tell me if there is a limit on the number of defines,
>> and if so, what that limit is?
>>
>> Thanks in advance!
>>
>> Ikke
>>>
>> While going through the code of an OS website, I noticed all the links were
>> replaced by defines. Everytime someone wanted to use a link, said link was
>> added to an included file, and echo'd in the page where the link should be.
>>
>> The entire include file (links.inc) consisted of lines like the following:
>> define('GOOGLE', '<a href="http://www.google.com/">Google</a>');
>>
>> At first I liked the idea - if you want to change a link, you only have to
>> change it once, which is quite a benefit.
>>
>> However, how many of these defines are allowed in PHP? I've had a quick
>> Google for an answer, but couldn't come up with a definitive answer.
>>
>> Could somebody please tell me if there is a limit on the number of defines,
>> and if so, what that limit is?
>>
>> Thanks in advance!
>>
>> Ikke
>More than you're likely to ever use. No hard limit, AFAIK, but you'll
>run into other constraints such as memory usage.
>
>The bigger problem will be parsing thousands of define statements which
>will never be used in the current script.
Is there any significant performance difference between using define()
and constants, versus assigning the values to variables? I use a
shared URL definition technique as well, but in this fashion :
$site_tld = 'www.domain.com';
$site_secure_url = 'https://' . $site_tld;
$url_contact_page = $site_secure_url . '/contact.php';
(The first two variables are used in other contexts, which is why
they're assigned separately.)
Would define()s be more or less memory efficient, or is the difference
so trivial that it's not worth real-world consideration?
Thanks.
Previous Thread: Trying to send mail with PEAR, php string problem
Next Thread: PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
Related Forum Topics
- Defines not working
- Re: Limit calls of script
- Warning: Redirection limit for url exceeded...
- Formatting a number
- Variable number of args
- Re: Checking equal number of and
- Phone number formatting
- Query shows only one telephone number
- Function to return the next sequential number
- Change a string where have number after a word