php-general Digest 2 Mar 2010 12:34:12 -0000 Issue 6617
Topics (messages 302462 through 302471):
Re: Best Practices Book, Document, Web Site?
302462 by: pan
302464 by: Rene Veerman
Error Message - Need help troubleshooting
302463 by: Rick Dwyer
302465 by: Rene Veerman
Re: HipHop and other PHP compiler performance evaluation
302466 by: Manuel Lemos
App to put a whole PHP Site in CD/DVD
302467 by: Juan
302469 by: Ashley Sheridan
OSSCamp Chandigarh April 2010 - Open Source Is The Future
302468 by: Rishabh Verma
Re: When to use namespaces
302470 by: Richard Quadling
Re: session.entropy_file and hostname
302471 by: Rene Veerman
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 ---
""Hansen, Mike"" <[email protected]> wrote in message
news:[email protected]...
Is there a PHP Best Practices Book, Document, or web site that has
information similar to Perl Best Practices but for PHP?
Yeah, it's hard to find this stuff.
A google search on {+"Best Practices" +"PHP"} returned only
4,340,000 hits.
Maybe, some day, someone will think to write something up.
Good luck.
--- End Message ---
--- Begin Message ---
http://oreilly.com/php/index.html perhaps?
I dont know any free online best practice docs (other than the php.net
function comments) that sum it all up nicely.
But best practices are like coding standards; there are at least a few
that are (near-)equals.
Personally, the basis of my current coding style is as such:
- hungarianCasingConventionWithAbbreviationsWTFlikeSo
- almost always short names for variables in simple code < 40 lines
- almost always longer and descriptive names for more complicated code.
- usually short comments: explanations for noobs (to problem area)
- the rest of the "commenting" is done by the code using descriptive
var & function names
(last 3 points makes for "self-documented code")
- consolidate all logic in the script, so use specific sets
(_POST/_GET) rather than generic sets (_REQUEST)
- document it in script if behaviour is dependent on outside sources
(like php.ini)
- use of "config.php" in project rootdir to set DEFINE()s and any
global variables.
- use of adodb.sf.net for database abstraction.
- use a standarized directory structure for all php projects;
/project/.htaccess - RewriteRule -> php scripts
/project/php - all php scripts
/project/js - all javascript, including .js.php
/project/lib/component-x.y.z/ - all 3rd party libraries, regardless
of language, x.y.z=versionnum
/project/sql - sql init / maintenance scripts
(possibly) /project/theme/themeName/many.css(.php)
(or:) /project/css/some.css(.php)
(possibly:) /project/admin/
- use of an error handler that knows when to mail errors to developer,
when to print errs in browser and when not to, etc.
a "proper error handler". mine is still evolving.
- use of a standard debug output lib, called by a function that checks
config.php for a DEBUG_MODE define. prevents production machines from
showing debug info.
plug: my free http://mediabeez.ws/htmlMicroscope/ is kinda nice.
- push all input into DB through functions that prevent SQL insertion
(at least a filter through mysql_real_escape) and HTML/js/flash/etc
insertions (harder).
- an authentication scheme that can be called with simple functions,
but which also does checks on whether or not the IP that started the
session is the same as the IP making a request on a certain session.
- calling of the authentication scheme by nearly all scripts
- in any lenghty operation, design for continuation of the operation
when a given item fails.
example from OS file copiers: it stops when it needs to ask a
question. i rather design to "keep going", log all items that require
user interaction, and let the user deal with them when he/she has
time.
there's probably more that would make it into my best practices list,
but i'm gonna leave it at this for now..
On Mon, Mar 1, 2010 at 9:48 PM, Hansen, Mike <[email protected]> wrote:
> Is there a PHP Best Practices Book, Document, or web site that has
> information similar to Perl Best Practices but for PHP?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hello List.
I have some JS code that open a new window with a contact form in it.
When the link is clicked to open the new window, I will get the
following error SOMETIMES:
"Warning: Unknown: Your script possibly relies on a session side-
effect which existed until PHP 4.2.3. Please be advised that the
session extension does not consider global variables as a source of
data, unless register_globals is enabled. You can disable this
functionality and this warning by setting session.bug_compat_42 or
session.bug_compat_warn to off, respectively. in Unknown on line 0"
My JS code with a bit of PHP in it looks like this:
function loadOSS()
var oss_itemid = "<?php echo $item_id; ?>";
var loadOSS = window.open("my_url/my_file.php?iid=" + oss_itemid, "",
"scrollbars
=
no
,menubar
=
no
,height=600,width=600,resizable=yes,toolbar=no,location=no,status=no");
}
As I said above, the error message does not always appear.
Is the error due to the fact I am JS & PHP together?
Any help in understanding what I am doing wrong is appreciated.
--Rick
--- End Message ---
--- Begin Message ---
i doubt you passed us the entire .js.php script..
does the script itself ever fail, asides from showing this msg?
On Tue, Mar 2, 2010 at 5:46 AM, Rick Dwyer <[email protected]> wrote:
> Hello List.
>
> I have some JS code that open a new window with a contact form in it. When
> the link is clicked to open the new window, I will get the following error
> SOMETIMES:
>
> "Warning: Unknown: Your script possibly relies on a session side-effect
> which existed until PHP 4.2.3. Please be advised that the session extension
> does not consider global variables as a source of data, unless
> register_globals is enabled. You can disable this functionality and this
> warning by setting session.bug_compat_42 or session.bug_compat_warn to off,
> respectively. in Unknown on line 0"
>
> My JS code with a bit of PHP in it looks like this:
>
> function loadOSS()
> var oss_itemid = "<?php echo $item_id; ?>";
> var loadOSS = window.open("my_url/my_file.php?iid=" + oss_itemid, "",
> "scrollbars=no,menubar=no,height=600,width=600,resizable=yes,toolbar=no,location=no,status=no");
> }
>
> As I said above, the error message does not always appear.
>
> Is the error due to the fact I am JS & PHP together?
>
> Any help in understanding what I am doing wrong is appreciated.
>
> --Rick
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hello,
on 03/02/2010 01:04 AM Raymond Irving said the following:
> Hi Manuel ,
>
> Thanks for the feedback.
>
> I know that caching helps but if we could get a little more speed out of
> the scripts then that would help with the number of request per second.
>
> I'll have a look at the article that you have recommend.
I am talking about content caching, not opcode caching. If you have a
page with contents do change frequently, you can use content caching
(files, memcached, etc). Then PHP execution speed will be mostly
irrelevant because your script will be waiting most of the time for I/O
operations copying data from cache files or memcached server and the
user computer.
> --- On *Fri, 2/26/10, Manuel Lemos /<[email protected]>/* wrote:
>
>
> From: Manuel Lemos <[email protected]>
> Subject: Re: [PHP] HipHop and other PHP compiler performance evaluation
> To: "Raymond Irving" <[email protected]>
> Cc: "PHP List" <[email protected]>
> Date: Friday, February 26, 2010, 12:52 AM
>
> Hello Raymond,
>
> on 02/25/2010 11:34 PM Raymond Irving said the following:
> >
> > Very nice article. Thanks for sharing.
> >
> > I wish PHP had a feature/extension to compile (to native code) and
> cache
> > the scripts at runtime. This way we could get speeds that are very
> close
> > to PHC and Hiphop. It would be very slow when loading the page for the
> > first time but after then it should just blaze. Maybe we will one day
> > see something like an NCC (Native Code Compiler) extension for php
> that
> > will replace or complement APC.
>
> Right but keep in mind that most of the time regular PHP scripts are
> waiting for I/O operations, like accessing to the network, files or
> database servers. So the speed of execution of pure CPU intensive code
> like bench.php used in the tests, may not be what matters most to your
> sites.
>
> So, often investing in heavily caching your content in files (or
> memcached servers for clustered servers) is a much more efficient
> solution to handle the load of busy sites. That is mostly what the
> PHPClasses sites uses to handle over 2 million page views a month with a
> single server.
>
> You may want to read more about that here for more details:
>
>
> http://www.phpclasses.org/blog/post/66-More-defensive-programming-practices-to-survive-Web-site-traffic-peaks.html
--
Regards,
Manuel Lemos
Find and post PHP jobs
http://www.phpclasses.org/jobs/
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
--- End Message ---
--- Begin Message ---
Hi,
I need an application to run mysql/php/apache or similar in one cd, to
make a presentation.
The presentation itself is a php site that uses mysql to do some
queries, to show data, and I would like to know how to embbed php and
mysql to one cd for a presentation. I mean; one cd containing the
whole site, and when the user inserts it on the cd/dvd reader it's
able to use the website like if him/her would be using the http
protocol. So, this application should let me put mysql/php/apache in
the cd, then it should work from the cd.
I would like to use some free software application, I would like to
avoid using commercial branches because I need this for a commercial
project that isn't able to pay licenses. Also I preffer Free Software.
So, if you know some appplication that helps me to develop this, and
also if I would be able to make the cd multiplatform for the principal
OS ( Gnu/linux, win, mac ) even better.
Thanks a lot.
Juan
--- End Message ---
--- Begin Message ---
On Tue, 2010-03-02 at 08:12 -0300, Juan wrote:
> Hi,
> I need an application to run mysql/php/apache or similar in one cd, to
> make a presentation.
>
> The presentation itself is a php site that uses mysql to do some
> queries, to show data, and I would like to know how to embbed php and
> mysql to one cd for a presentation. I mean; one cd containing the
> whole site, and when the user inserts it on the cd/dvd reader it's
> able to use the website like if him/her would be using the http
> protocol. So, this application should let me put mysql/php/apache in
> the cd, then it should work from the cd.
>
> I would like to use some free software application, I would like to
> avoid using commercial branches because I need this for a commercial
> project that isn't able to pay licenses. Also I preffer Free Software.
>
> So, if you know some appplication that helps me to develop this, and
> also if I would be able to make the cd multiplatform for the principal
> OS ( Gnu/linux, win, mac ) even better.
>
> Thanks a lot.
>
> Juan
>
If you want this sort of setup, then why not go with a live Linux CD/DVD
that has the website on. You can lock the live OS down so that it is in
what's called a kiosk mode, which should meet your requirements.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Hello All,
OSSCamp is again being organized in Chandigarh on April 10, 2010. This is
another step ahead to foster the open source community in the city
beautiful. At a Camp, we love to cross-talk, huddle together, raise some
noise, celebrate technology, argue over the coolest OS ever made, fight on
our fav programming languages, discuss stuff, and what not! PHP and other
open source web development technologies will be a major part of the
discussion at the camp. Would be great if you all join us at the the camp.
OSScamp Chandigarh April 2010
April 10, 2009
Venue:To Be Decided
Time: 10AM - 6PM
You can register for the event at : http://chd.osscamp.in/
Follow Us on Twitter : http://twitter.com/osscamp
Facebook Event Page :
--
Regards,
Rishabh Verma
c. +91.98555.17272
Follow me on twitter : www.twitter.com/rishabhverma
Add me on Facebook : www.facebook.com/rishabhv
The Teen Tech Junkie
--- End Message ---
--- Begin Message ---
On 1 March 2010 19:34, Adam Richardson <[email protected]> wrote:
> I use namespaces within my web framework because the framework takes a more
> functional approach (no objects are created within the framework other than
> from existing classes such as PDO or Exception, immutability is promoted,
> etc.), and in this context, the namespaces felt quite natural for breaking
> up the various groupings of functions.
>
> My framework does require PHP 5.3, and, honestly that has caused some pain
> in some situations to get that supported.
>
> However, using namespaces does offer some flexibility that naming
> conventions can't. If the objects in your framework make use of frequent
> static method calls, maybe it's worth it. For instance, if you've used the
> naming convention, you might have to call a static method like below:
>
> App_Util_DB_Query::Insert();
>
> Namespaces allow you to shorten subsequent calls, such as:
>
> use App\Util\DB\Query as Query;
>
> Query::Insert();
>
> Just a quick couple thoughts on the decision. Both have their strengths :)
>
> Adam
>
> On Mon, Mar 1, 2010 at 11:14 AM, Auke van Slooten <[email protected]> wrote:
>
>> Hi everyone,
>>
>> I'm doing a small hobby project to better my understanding of php5,
>> specifically php5.3 and I'm wondering when a namespaced project is better
>> and when it is better to simply use a prefix to all class names.
>>
>> I've been trying to get a feeling for what is considered the best practice,
>> but most of the pages dealing with namespaces start with the assumption that
>> you are building a complex application with lots of modules and say things
>> like:
>>
>> Namespaces should be all lowercase and must follow the following conention:
>> <vendor>\<package_name>\
>>
>> (thats from the php.standards mailing list btw)
>>
>> In my case the project is a single module, single php file, with about 6
>> classes. It is an OO wrapper for PHP's xmlrpc methods (client and server)
>> and meant to be used in a number of different projects.
>>
>> Is it considered a good idea to use a namespace in such a case? And if so,
>> what should that be? I've named the project 'ripcord', and used that as a
>> namespace as well. I could probably name it 'muze.ripcord', but somehow that
>> feels less 'open' to me.
>>
>> Thanks in advance for any thoughts,
>> Auke van Slooten
>> Muze (www.muze.nl)
>>
>> PS. The project is at http://code.google.com/p/ripcord/, the PHP5.3
>> version is at
>> http://code.google.com/p/ripcord/source/browse/#svn/branches/php5.3
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> --
> Nephtali: PHP web framework that functions beautifully
> http://nephtaliproject.com
>
Something I came across which has been useful in removing the long
names (<php5.3 namespaces), is the use of class_alias().
My specific use is in DocBlocks for SOAP services. Using the Zend
AutoLoader, my classes are structured so that
Namespace_Package_Class_Exception is available in
\includes\Namespace\Package\Class\Exception.php
But having those long names in the SOAP WSDL file were a bit
cumbersome. So by having a class_alias in the important class files
(just after the class definition), I could use the alias names in the
docblock and all is well.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
If you want server-unique session ids, use session_name() before
session_start()..?
session.entropy_file seems to be used only with /dev/urandom,
and seems to be used to _increase_ the differences betweeen
session ids.
On Mon, Mar 1, 2010 at 5:49 PM, Sascha Wojewsky
<[email protected]> wrote:
> Hi,
>
> i'm new to this list...
> Is it possible to set the session.entropy_file to /bin/hostname (or
> something like this)?
> I've to user server-unique SessionIDs...
>
> Thanks
>
> Sascha
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---