php-general Digest 29 Nov 2010 23:54:35 -0000 Issue 7061

2010-11-29 Thread php-general-digest-help

php-general Digest 29 Nov 2010 23:54:35 - Issue 7061

Topics (messages 309743 through 309754):

Re: Disk IO performance
309743 by: Per Jessen
309744 by: Daniel Molina Wegener

Poor newsgroup server performance
309745 by: Al
309746 by: Daniel P. Brown
309747 by: Al
309748 by: Daniel Brown
309749 by: Steve Staples

EE1 plugin code/htmlentities() question
309750 by: Micky Hulse

mySQL query assistance...
309751 by: Don Wieland
309752 by: Daniel P. Brown
309753 by: Daniel P. Brown

Form Processing
309754 by: Ron Piggott

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Daniel Molina Wegener wrote:

 On Sunday 28 November 2010,
 Larry Garfield la...@garfieldtech.com wrote:
 
 There are many things that everybody knows about optimizing PHP
 code. One of them is that one of the most expensive parts of the
 process is loading code off of disk and compiling it, which is why
 opcode caches
 are such a bit performance boost.  The corollary to that, of course,
 is that more files = more IO and therefore more of a performance hit.
 
   It depends on the implementation that PHP uses to open the file. For
 example on Linux and similar operating systems, PHP uses the mmap(2)
 function instead of read(2) or fread(2) functions, so it maps the
 complete file into memory, that is more faster than using partial file
 reads.

I doubt if a read(file,1Mb) and an mmap(file,1Mb) will be very
different.  The file has got to be hauled in from disk regardless of
which function you choose. 



-- 
Per Jessen, Zürich (2.6°C)

---End Message---
---BeginMessage---
On Monday 29 November 2010,
Per Jessen p...@computer.org wrote:

 Daniel Molina Wegener wrote:
  On Sunday 28 November 2010,
  
  Larry Garfield la...@garfieldtech.com wrote:
  There are many things that everybody knows about optimizing PHP
  code. One of them is that one of the most expensive parts of the
  process is loading code off of disk and compiling it, which is why
  opcode caches
  are such a bit performance boost.  The corollary to that, of course,
  is that more files = more IO and therefore more of a performance hit.
  
It depends on the implementation that PHP uses to open the file. For
  
  example on Linux and similar operating systems, PHP uses the mmap(2)
  function instead of read(2) or fread(2) functions, so it maps the
  complete file into memory, that is more faster than using partial file
  reads.
 
 I doubt if a read(file,1Mb) and an mmap(file,1Mb) will be very
 different.  The file has got to be hauled in from disk regardless of
 which function you choose.

  Well, they are different. That's why some php functions and a wide
variety of language implementations are using mmap(2) instead of read(2)
to read files from the hard drive for inclusion or module importing.
Also Apache uses sendfile(2) and mmap(2) when they are available on
the platform because are more faster than read(2).

  You just can trace how php loads certain modules when you call
include(), require(), include_once() and require_once(). Also Python,
Perl and other languages have a similar implementation when they
are loading modules.

  read(2) depends on the VFS blocksize, which is used as the maximum
unit for chunk reads, mmap(2) not.

  Just check the PHP source code or run an strace(1) over php loading
modules and check which function is used to read inclusions.

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.
---End Message---
---BeginMessage---

Recently the response on our php.general php.pear.general have become horribly 
slow.

At first I thought the problem was a time-of-day overload; but, it seems to be 
happening at all times.


All other websites I visit are normal.

Just getting to post this message took 2 timeouts.

---End Message---
---BeginMessage---
On Mon, Nov 29, 2010 at 09:14, Al n...@ridersite.org wrote:
 Recently the response on our php.general php.pear.general have become
 horribly slow.

 At first I thought the problem was a time-of-day overload; but, it seems to
 be happening at all times.

 All other websites I visit are normal.

 Just getting to post this message took 2 timeouts.

Via what news server(s), Al?

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
---End Message---
---BeginMessage---



On 11/29/2010 11:03 AM, Daniel P. Brown wrote:

On Mon, Nov 29, 2010 at 09:14, Aln...@ridersite.org  wrote:

Recently 

Re: [PHP] Disk IO performance

2010-11-29 Thread Daniel Molina Wegener
On Sunday 28 November 2010,
Larry Garfield la...@garfieldtech.com wrote:

 There are many things that everybody knows about optimizing PHP code. 
 One of them is that one of the most expensive parts of the process is
 loading code off of disk and compiling it, which is why opcode caches
 are such a bit performance boost.  The corollary to that, of course, is
 that more files = more IO and therefore more of a performance hit.

  It depends on the implementation that PHP uses to open the file. For
example on Linux and similar operating systems, PHP uses the mmap(2)
function instead of read(2) or fread(2) functions, so it maps the complete
file into memory, that is more faster than using partial file reads.

 
 But... this is 'effin 2010.  It's almost bloody 2011.  Operating systems
 are smart.  They already have 14 levels of caching built into them from
 hard drive micro-controller to RAM to CPU cache to OS.  I've heard from
 other people (who should know) that the IO cost of doing a file_exists()
 or other stat calls is almost non-existent because a modern OS caches
 that, and with OS-based file caching even reading small files off disk
 (the size that most PHP source files are) is not as slow as we think.

  Yes, that's true. This point depends on how the operating system has
implemented it's VFS. Linux, FreeBSD and other platforms, have a well
done implementation of VFSs, so they have a good cache implementation
for concurrent reads, and first read on a file is made /hard/, then it
uses the cached file location (inode data).

 
 Personally, I don't know.  I am not an OS engineer and haven't
 benchmarked such things, nor am I really competent to do so.  However,
 it makes a huge impact on the way one structures a large PHP program as
 the performance trade- offs of huge files with massive unused code (that
 has to be compiled) vs the cost of reading lots of separate files from
 disk (more IO) is highly dependent on the speed of the aforementioned IO
 and of compilation.

  You can do your own benchmarks tests, from high level perspective or
low level perspective. If you want to trace performance on how PHP reads
files from the hard drive, you can use some extensions like xdebug.

  For example if you prefer to use require() and include(), instead of
require_once() and include_once() for concurrent reads, probably you
will get a lower performance because you will do real concurrent reads
on certain files.

 
 So... does anyone have any actual, hard data here?  I don't mean I
 think or in my experience.  I am looking for hard benchmarks,
 profiling, or writeups of how OS (Linux specifically if it matters) file
 caching works in 2010, not in 1998.

  Well, it also depends on the operating system configuration. If you
just want to know the performance of IO functions on PHP, I suggest to
use an extension like xdebug. It can generate profiling information to
be used with kcachegrind, so you can properly visualize how are working
IO functions in php.

  Probably a mmap(2) extension for PHP would be useful for certain kind
of files. The file_get_contents() function uses open(2)/read(2), so you 
can't do a quick on a file.

 
 Modernizing what everyone knows is important for the general community,
 and the quality of our code.
 
 --Larry Garfield

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


[PHP] Poor newsgroup server performance

2010-11-29 Thread Al

Recently the response on our php.general php.pear.general have become horribly 
slow.

At first I thought the problem was a time-of-day overload; but, it seems to be 
happening at all times.


All other websites I visit are normal.

Just getting to post this message took 2 timeouts.


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



Re: [PHP] Poor newsgroup server performance

2010-11-29 Thread Al



On 11/29/2010 11:03 AM, Daniel P. Brown wrote:

On Mon, Nov 29, 2010 at 09:14, Aln...@ridersite.org  wrote:

Recently the response on our php.general php.pear.general have become
horribly slow.

At first I thought the problem was a time-of-day overload; but, it seems to
be happening at all times.

All other websites I visit are normal.

Just getting to post this message took 2 timeouts.


 Via what news server(s), Al?



news.php.net

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



Re: [PHP] Poor newsgroup server performance

2010-11-29 Thread Daniel Brown
On Mon, Nov 29, 2010 at 12:52, Al n...@ridersite.org wrote:
 On 11/29/2010 11:03 AM, Daniel P. Brown wrote:

     Via what news server(s), Al?


 news.php.net

Okay, figured as much.  I had mentioned some time ago that I would
look into adding an NNTP-only mirror of news.php.net because of those
issues, so I'll get to work on that this week.  I'm working to revamp
some of the php.net infrastructure as it is, so that won't be too much
additional work.

(Famous last words)

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Poor newsgroup server performance

2010-11-29 Thread Steve Staples
On Mon, 2010-11-29 at 13:01 -0500, Daniel Brown wrote:
 On Mon, Nov 29, 2010 at 12:52, Al n...@ridersite.org wrote:
  On 11/29/2010 11:03 AM, Daniel P. Brown wrote:
 
  Via what news server(s), Al?
 
 
  news.php.net
 
 Okay, figured as much.  I had mentioned some time ago that I would
 look into adding an NNTP-only mirror of news.php.net because of those
 issues, so I'll get to work on that this week.  I'm working to revamp
 some of the php.net infrastructure as it is, so that won't be too much
 additional work.
 
 (Famous last words)
 
 -- 
 /Daniel P. Brown
 Network Infrastructure Manager
 Documentation, Webmaster Teams
 http://www.php.net/
 
i remember telling a client that..  oh yeah, you're just moving cpanel
accounts to a new cpanel server... shoulnd't take more than a few hours
to copy it over, and dns to propagate..   36 hours later, and no
sleep... i got it done... barely in time for his clients to log back in
at 8am... that was a stressful weekend... 

steve


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



[PHP] EE1 plugin code/htmlentities() question

2010-11-29 Thread Micky Hulse
Hello,

I was looking at this ExpressionEngine plugin:

http://expressionengine.com/downloads/details/xml_encode/
Description: This plugin converts reserved XML characters to entities.
 It is used in the RSS templates.

... Curious about this code:

trim(str_replace(array('#47;', 'nbsp;'), array(/, '#160;'), $str));

The plugin author used the above bit of code in the return statement.

Just curious if their is any particular reason why one would want to
replace #47; and nbsp; with / and #160 respectively?

For example, I am writing a similar plugin which utilizes
htmlentities()... I guess I am just wondering if I should apply the
same code as above to my entity-converted string?

Thoughts?

Thanks!
Micky

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



[PHP] mySQL query assistance...

2010-11-29 Thread Don Wieland

Hi all,

Is there a list/form to get some help on compiling mySQL queries? I am  
executing them via PHP, but do not want to ask for help here if it is  
no the appropriate forum. Thanks ;-)


Don

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



Re: [PHP] mySQL query assistance...

2010-11-29 Thread Daniel P. Brown
On Mon, Nov 29, 2010 at 14:35, Don Wieland d...@dwdataconcepts.com wrote:
 Hi all,

 Is there a list/form to get some help on compiling mySQL queries? I am
 executing them via PHP, but do not want to ask for help here if it is no the
 appropriate forum. Thanks ;-)

Yes.

For MySQL queries, write to the MySQL General list at
my...@lists.mysql.com.  For PHP-specific database questions (for any
database backend, not strictly MySQL), such as problems in connecting
to the database, questions on support for database platform/version,
or even query processing, you should use php...@lists.php.net.

For your convenience, both have been CC'd on this email.

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] mySQL query assistance...

2010-11-29 Thread Daniel P. Brown
On Mon, Nov 29, 2010 at 14:40, Daniel P. Brown
daniel.br...@parasane.net wrote:
    For your convenience, both have been CC'd on this email.

Actually, PHP-DB (php...@lists.php.net) was accidentally BCC'd.

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



[PHP] Form Processing

2010-11-29 Thread Ron Piggott

I am unable to retrieve the value of $referral_1 from: 

$new_email = mysql_escape_string ( $_POST['referral_$i'] );

why?

PHP while lopp to check if any of the fields were populated:



$i=1;
while ( $i = 5 ) {

$new_email = mysql_escape_string ( $_POST['referral_$i'] );

if ( strlen ( $new_email )  0 ) {

}

}


The form itself:


form method=post action=”website”

p style=margin: 10px 50px 10px 50px;input type=text name=email 
maxlength=60 class=referral_1 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email 
maxlength=60 class=referral_2 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email 
maxlength=60 class=referral_3 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email 
maxlength=60 class=referral_4 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email 
maxlength=60 class=referral_5 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=submit name=submit 
value=Add New Referrals/p

/form


What am I doing wrong?

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


Re: [PHP] Fw: Spoofing user_agent

2010-11-29 Thread Ron Piggott

My issue with the user agent is unresolved.  I need to do more research to see 
how AWSTATS distinguishes between a robot crawling the site and a web page user 
and set the user-agent accordingly.

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


From: Shreyas Agasthya 
Sent: Monday, November 29, 2010 1:35 AM
To: Ron Piggott 
Cc: PHP General List 
Subject: Re: [PHP] Fw: Spoofing user_agent

Ron, 

Can you let us know if this whole thing that you were trying to do worked? I 
see that very few actually bring a thread to a logical conclusion either by 
correcting the members here with the proposed fixes or letting the concerned 
set of people that they were right as rain. We should perhaps make this a 
practice and mandate so that the archives are utilized better. Correct me if I 
am wrong. 

Regards,
Shreyas


RE: [PHP]any way to iterate the fields in a class

2010-11-29 Thread Daevid Vincent
 

 -Original Message-
 From: ?? [mailto:xiaohan2...@gmail.com] 
 Sent: Thursday, November 25, 2010 12:21 AM
 To: php-general@lists.php.net
 Subject: [PHP]any way to iterate the fields in a class
 
 Actually, what I am seeking is how to assign values to the 
 fields in a class
 via an array.
 I have tried like this. However failed.
 I have a class.
 *class book{
 var name;*
 *var price;*
 *}*
 *
 *
 And I have got an array.
 
 *$array=array('name'='harry potter','price'='$122');*
 
 By using function *extract(), *I assign the values to $name 
 and $price while
 not $this-name and $this-price, which is not what I want.
 
 So I am thinking iterating the fields in an array and assign 
 the values each
 by each through an array.
 
 Is there any way to assign values to the fields in a class 
 via an array.
 
 Thanks in advance!
 


/**
* generate a key/value pair from the class' variables.
*
* @access   public
* @return   array
* @author   Daevid Vincent [daevid.vinc...@panasonic.aero]
* @version 1.0
* @date 01/27/09
*/
public function get_array()
{
$row = array();
foreach($this as $key = $value)
$row[$key] = $value;

return $row;
}


/**
* Shows all exposed variables in this class
*
* @access   public
* @return   array
* @paramboolean $print to print out each value
* @author   Daevid Vincent [daevid.vinc...@panasonic.aero]
* @version 1.1
* @date 01/27/09
*/
public function iterate_visible($print = false)
{
if ($print) echo
\nBRB.$this-get_class_name().::iterateVisible:/BBR\n;

$tmp = array();
foreach($this as $key = $value)
{
$tmp[$key] = $value;
if ($print) print $key. = .$value.BR\n;
}

return $tmp;
}


And related:

/**
* Provides generic getters and setters
*
* @access   public
* @param   string $method The method name.
* @param   array $arguments The arguments passed to the method.
* @return   mixed
* @author   Daevid Vincent [daevid.vinc...@panasonic.aero]
* @date 02/02/09
* @see  __get(), __set()
*/
public function __call( $method, $arguments )
{
$prefix = strtolower( substr( $method, 0, 3 ) );
$property = strtolower( substr( $method, 4 ) );

if ( empty($prefix) || empty($property) ) return;
//exit(__call($method) :: prefix='$prefix' and
property='$property');

if ( 'get' == $prefix )
{
if ( property_exists($this, $property) )
return $this-$property;
else
return $this-__get($property);
}
elseif ( 'set' == $prefix )
{
if ( property_exists($this, $property) )
return $this-$property = $arguments[0];
else
return $this-__set($property,
$arguments[0]);
}

// Technically we should never get to this point as most
calls are get_() or set_()
echo pfont color='#ff'Attempted to
'.$prefix.-.$method.()' in class
'.$this-get_class_name().'./fontp\n;
backtrace();
}

/**
* magic function to handle any accessing of undefined variables.
* Since PHP is lax this will help prevent stupid mistakes.
*
* @access   public
* @return   void
* @parammixed $property name of the variable
* @author   Daevid Vincent [daevid.vinc...@panasonic.aero]
* @date 2010-08-12
* @see  __set(), __call()
*/
public function __get($property)
{
if ($_SESSION['DEVELOPMENT']  !$_SESSION['mobile'])
{
echo pfont color='#ff'Attempted to __get()
non-existant property/variable '.$property.' in class
'.$this-get_class_name().'./fontp\n;
$this-suggest_alternative($property);
backtrace();
exit;
}
//else exit(__get($property) NO SUCH PROPERTY IN
.$this-get_class_name().' CLASS');
//[dv] commented this out as it was obviously exiting on
PROD, when really it should just ignore

//Throw new BadProperty($this, 'get', $property);
}

/**
* magic function to handle any setting of undefined variables.
   

Re: [PHP] Form Processing

2010-11-29 Thread Daniel Molina Wegener
On Monday 29 November 2010,
Ron Piggott ron.pigg...@actsministries.org wrote:

 I am unable to retrieve the value of $referral_1 from:

  That's very simple, you are missing the name attribute for
your input elements, for example:

input type=text name=email
   maxlength=60 class=referral_5
   style=width: 400px;

  Should be:

input type=text name=email
   maxlength=60 class=referral_5 name=referral_5
   style=width: 400px;

  Please read the following links:

HTML Standards:
http://www.w3.org/standards/webdesign/htmlcss

PHP Manual:
http://cl.php.net/manual/en/

 
 $new_email = mysql_escape_string ( $_POST['referral_$i'] );
 
 why?
 
 PHP while lopp to check if any of the fields were populated:
 
 
 
 $i=1;
 while ( $i = 5 ) {
 
 $new_email = mysql_escape_string ( $_POST['referral_$i'] );
 
 if ( strlen ( $new_email )  0 ) {
 
 }
 
 }
 
 
 The form itself:
 
 
 form method=post action=”website”
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_1 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_2 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_3 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_4 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_5 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=submit
 name=submit value=Add New Referrals/p
 
 /form
 
 
 What am I doing wrong?
 
 Ron
 
 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] Form Processing

2010-11-29 Thread Daniel P. Brown
On Mon, Nov 29, 2010 at 18:54, Ron Piggott
ron.pigg...@actsministries.org wrote:

 $new_email = mysql_escape_string ( $_POST['referral_$i'] );

Because you're using literal quotes, so PHP is literally looking
for the POST reference 'referral_$i'.

Instead of using the style of field names you're using, why not
use a virtually limitless array?

?php

if (isset($_POST['referral'])  is_array($_POST['referral'])) {
$refcnt = count($_POST['referral']);
for ($i=0;$i$refcnt;$i++) {
echo 'Referral #'.$i.': '.$_POST['referral'][$i].'br/'.PHP_EOL;
}
}
?
form method=post action=?php echo $_SERVER['PHP_SELF']; ?
?php
for ($i=1;$i6;$i++) {
echo ' nbsp; nbsp;input type=text name=referral[]
id=referral_'.$i.'/br/'.PHP_EOL;
}
?
input type=submit id=submitButton value=Send/
/form

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Fw: Spoofing user_agent

2010-11-29 Thread Thiago H. Pojda
Quit top posting.

On Mon, Nov 29, 2010 at 9:55 PM, Ron Piggott ron.pigg...@actsministries.org
 wrote:


 My issue with the user agent is unresolved.  I need to do more research to
 see how AWSTATS distinguishes between a robot crawling the site and a web
 page user and set the user-agent accordingly.


Ron,

AWSTATS probably users a knowledge base for known bots, I'm not sure. If
that's the case, you can just set your User-Agent to a known and see how
that goes.

Look for Googlebot, Majestic, Ask.com (now dead - probably a good pick),
MSNBot here: http://www.user-agents.org/

As for setting the User-Agent in your request, I like to use this cUrl
snippet (based on a note at curl's manual page):

?php

  $sUrl = 'www.example.com/';
  $sUserAgent = 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)';

  $hCurl = curl_init();
  curl_setopt ($hCurl, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt ($hCurl, CURLOPT_URL, $sUrl);
  curl_setopt ($hCurl, CURLOPT_CONNECTTIMEOUT, 120);
  curl_setopt ($hCurl, CURLOPT_TIMEOUT, 120);
  curl_setopt ($hCurl, CURLOPT_USERAGENT, $sUserAgent);

  $sContent = curl_exec($hCurl);
?


Cheers,
Thiago Henrique Pojda
+55 41 8856-7925