php-general Digest 6 Jan 2011 15:13:18 -0000 Issue 7118
Topics (messages 310512 through 310521):
Re: Newbie Question
310512 by: sono-io.fannullone.us
310515 by: tedd
310518 by: David Harkness
310520 by: Daniel Brown
Global or include?
310513 by: Paul Halliday
310514 by: Nicholas Kell
310516 by: Nathan Nobbe
310517 by: Nathan Nobbe
310519 by: David Harkness
Memory_Limit adjustments
310521 by: Rick Dwyer
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Jan 4, 2011, at 5:27 AM, Steve Staples wrote:
> I now use Komodo (the free version) on my ubuntu workstation, and I love
> it... I dont know how I managed before.
I use Komodo Edit on OS X and I love it as well, except for the compare
files feature. It's the worst one I've ever used. TextWrangler is far
superior for file comparisons.
Marc
--- End Message ---
--- Begin Message ---
At 8:32 AM -0800 1/5/11, David Harkness wrote:
On Wed, Jan 5, 2011 at 8:20 AM, tedd
<<mailto:[email protected]>[email protected]> wrote:
I teach using NetBeans, because it generally sucks less than
Eclipse. Eclipse is simply too complicated and NetBeans tries to be
less, but it's still too much.
Have you tried PHPStorm?
-snip-
David
David:
Thank you very much for your suggestion.
I spent a couple of hours reviewing PHPStorm and it looks *very* promising!
Not only is it relatively cheap ($49), but they have an option for
teaching a classroom (they will contact me for details). In short, it
looks like it was made for me.
Plus, they have versions for both Windozes and Mac. I use Mac
personally/professionally but am forced to teach programming on
Windozes. I find that schools are slow to learn when they follow
Corporate America and Governments as examples of the "right way" to
do things. Instead they should look at the success of General Motors
and the State of California for "their way" to handle budgets and
conclude these examples are not as smart as they should be -- but I
digress.
The paths required for files (local/remote) are not as obvious as I
would like, nor does the program actually have control over the
placement of files (IOW it does NOT allow drag/drop of files and
folders within the program), but I understand that may be more than
what they can master for both both platforms. Maybe that will come
later.
However, it does an automatic update of files that have been changed
and can run a local and remote execution of the code -- so it is very
useful.
One of the things that it has over NetBeans and Eclipse is that it
can provide a review of the files that are on the remote server,
which was one of my major complaints against both NetBeans and
Eclipse.
Thanks again.
Cheers,
tedd
--
-------
http://sperling.com/
--- End Message ---
--- Begin Message ---
On Wed, Jan 5, 2011 at 3:05 PM, tedd <[email protected]> wrote:
> I spent a couple of hours reviewing PHPStorm and it looks *very* promising!
Thank you for sharing your thoughts on PHPStorm. My main performance gripe
with NetBeans has lessened in the year I've been using it, so I'm less
inclined to go up yet another learning curve, but it's always helpful to get
input on the competitors. Please let us know if you end up using it in your
class as I'm sure others will enjoy reading your findings.
I spent about 10 minutes looking over the feature set of Komodo which was
recommended by Steve Staples in this thread, and it also looks quite
impressive. it's more expensive for the IDE (the stand-alone editor is free)
which does remote file-syncing ($295), but you might be able to swing an
educational discount with them. Most companies will gladly give their
product away to put it in the hands of soon-to-be-professionals. :)
Good luck!
David
--- End Message ---
--- Begin Message ---
On Wed, Jan 5, 2011 at 19:45, David Harkness <[email protected]> wrote:
[snip!]
>
> Most companies will gladly give their product away to put it in the hands of
> soon-to-be-professionals. :)
Tedd had his chance to be professional back in the forties (the
eighteen-forties, I believe). Now he teaches others who still have a
chance. ;-P
Which reminds me of an old thread from back in 2008, where I
posted Tedd's senior class picture. You can see it here:
http://links.parasane.net/tb46
--
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/
--- End Message ---
--- Begin Message ---
Say you have 10 or so scripts and a single config file. If you have
main.php, functions1.php, functions2.php, functions3.php..
Does is hurt to do an include of the config file in each separate
script, even if you only need a few things from it, or should you
just specify what you want with a 'global' within each
script/function?
Thanks!
--
Paul Halliday
http://www.pintumbler.org
--- End Message ---
--- Begin Message ---
On Jan 5, 2011, at 4:40 PM, Paul Halliday wrote:
> Say you have 10 or so scripts and a single config file. If you have
> main.php, functions1.php, functions2.php, functions3.php..
>
> Does is hurt to do an include of the config file in each separate
> script, even if you only need a few things from it, or should you
> just specify what you want with a 'global' within each
> script/function?
>
> Thanks!
>
> --
> Paul Halliday
> http://www.pintumbler.org
I think that OOP would solve this particular problem best.
--- End Message ---
--- Begin Message ---
On Wed, Jan 5, 2011 at 3:40 PM, Paul Halliday <[email protected]>wrote:
> Say you have 10 or so scripts and a single config file. If you have
> main.php, functions1.php, functions2.php, functions3.php..
>
> Does is hurt to do an include of the config file in each separate
> script, even if you only need a few things from it, or should you
> just specify what you want with a 'global' within each
> script/function?
>
touching on what Nicholas said this could be handled in OOP via the
singleton pattern, however there are ways of dealing w/ it in global
function land as well.
i see 4 immediate options
. load config from each file (performance hit mitigated if config is a php
array and using opcode caching)
. global variable
. session storage
. config fetching function w/ static variable
the last option is the one i'd like to describe since i think its the
cleanest, even if you have opcode caching enabled. the function would look
something like this
function load_config()
{
static $cachedConfig = null;
if($cachedConfig !== null)
{
// load file and store value(s) in $cachedConfig
}
return $cachedConfig;
}
now all you have to do is make load_config() available in all your files,
via something like require_once on the file which defines load_config().
the result is the configuration will only be read once on a given page
load, thereafter its contents will come from memory.
this is actually very similar to the singleton approach in OOP.
-nathan
--- End Message ---
--- Begin Message ---
On Wed, Jan 5, 2011 at 4:27 PM, Nathan Nobbe <[email protected]> wrote:
> On Wed, Jan 5, 2011 at 3:40 PM, Paul Halliday <[email protected]>wrote:
>
>> Say you have 10 or so scripts and a single config file. If you have
>> main.php, functions1.php, functions2.php, functions3.php..
>>
>> Does is hurt to do an include of the config file in each separate
>> script, even if you only need a few things from it, or should you
>> just specify what you want with a 'global' within each
>> script/function?
>>
>
> touching on what Nicholas said this could be handled in OOP via the
> singleton pattern, however there are ways of dealing w/ it in global
> function land as well.
>
> i see 4 immediate options
> . load config from each file (performance hit mitigated if config is a php
> array and using opcode caching)
> . global variable
> . session storage
> . config fetching function w/ static variable
>
> the last option is the one i'd like to describe since i think its the
> cleanest, even if you have opcode caching enabled. the function would look
> something like this
>
> function load_config()
> {
> static $cachedConfig = null;
>
> if($cachedConfig !== null)
> {
> // load file and store value(s) in $cachedConfig
> }
>
> return $cachedConfig;
> }
>
> now all you have to do is make load_config() available in all your files,
> via something like require_once on the file which defines load_config().
> the result is the configuration will only be read once on a given page
> load, thereafter its contents will come from memory.
>
> this is actually very similar to the singleton approach in OOP.
>
> -nathan
>
UMM, check that, the conditional should read
if($cachedConfig === null)
{
// load config file :)
$cachedConfig = $someValue; // ...
}
my bad, lol!
-nathan
--- End Message ---
--- Begin Message ---
On Wed, Jan 5, 2011 at 3:27 PM, Nathan Nobbe <[email protected]> wrote:
> if($cachedConfig !== null)
> {
> // load file and store value(s) in $cachedConfig
> }
>
"No config for you ... one year!"
Sorry, couldn't resist. :p
To expand on Nathan's excellent strategy, you could go one further and add
functions to config.php to return specific values from the config instead of
exposing the raw config object. This will have benefits if you change the
structure of the config later and only have to change your access code in
one place. It also replaces client code such as
$config = load_config();
if ($config['facebook']['enabled']) { ... }
with the more readable
if (isFacebookEnabled()) { ... }
by adding an access function in config.php:
function isFacebookEnabled() {
$config = load_config();
return (bool) $config['facebook']['enabled'];
}
You would still require_once 'config.php', but now you don't have to expose
knowledge of the config's internal structure to every script that needs to
access it.
David
--- End Message ---
--- Begin Message ---
Hello all.
I am using a form combined with PHP to upload files to a website
directory.
Worked fine until I tried to upload a file 1.7 mb in size. My php
code isn't the bottleneck as I scan the file first and reject the
upload request if it exceed 4096KB.
So I looked at the php.ini file and tweaked some settings. Once I
changed the Memory_Limit setting from 8mb to 28mb, the file upload
without a problem.
So, my question is, is the 28mb setting going to cause problems
elsewhere on the server or is this a relatively modest setting?
Should I adjust it further?
The server is a Linux server running Apache 1.3.37 with PHP version
5.2.3.
Current memory usage as follows:
Current Memory Usage
total used free
Mem: 21898120 283912 21614208
-/+ buffers/cache: 283912 21614208
Swap: 0 0 0
Total: 21898120 283912 21614208
Thanks for any help.
--Rick
--- End Message ---