php-general Digest 2 Aug 2009 03:54:05 -0000 Issue 6262

Topics (messages 296164 through 296173):

Newbie: can't access a return value.
        296164 by: MEM
        296166 by: TG
        296167 by: MEM

Re: clean url problem .htaccess
        296165 by: O. Lavell
        296170 by: HallMarc Websites
        296171 by: HallMarc Websites

Re: Clean break.
        296168 by: ollisso

Re: 2 ifs embedded? (RESOLVED)
        296169 by: Colin Guthrie

PHP programming strategy
        296172 by: Clancy
        296173 by: Larry Garfield

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


----------------------------------------------------------------------
--- Begin Message ---
Hi all,

When I do this:
$associacao_dao->listar($limit, $offset);

I can var_dump the correct $limit.
I can var_dump the correct $offset.

I CAN'T access the object that I was hoping to get, called $records.

After this, I was hoping to do var_dump($records); and see the stdClass
object. 




Here is the listar method:

public function listar($limit=null, $offset=null) 
{
        $query_str="SELECT * FROM associacao";
                        
        $stmt = $this->_dbh->prepare($query_str . ' LIMIT ?, ?');
        $stmt->bindParam(1, $limit, PDO::PARAM_INT);
        $stmt->bindParam(2, $offset, PDO::PARAM_INT);
                        
        $stmt->execute();
                                
        $records = $stmt->fetchAll(PDO::FETCH_OBJ);
                                        
        return $records;                
}



Any help will be greatly appreciated.


Thanks a lot in advance,
Márcio


--- End Message ---
--- Begin Message ---
Try:

$records = $associacao_dao->listar($limit, $offset);

-TG

----- Original Message -----
From: "MEM" <tal...@gmail.com>
To: <php-gene...@lists.php.net>
Date: Sat, 1 Aug 2009 17:13:09 +0100
Subject: [PHP] Newbie: can't access a return value.

> Hi all,
> 
> When I do this:
> $associacao_dao->listar($limit, $offset);
> 
> I can var_dump the correct $limit.
> I can var_dump the correct $offset.
> 
> I CAN'T access the object that I was hoping to get, called $records.
> 
> After this, I was hoping to do var_dump($records); and see the stdClass
> object. 
> 
> 
> 
> 
> Here is the listar method:
> 
> public function listar($limit=null, $offset=null) 
> {
>       $query_str="SELECT * FROM associacao";
>                       
>       $stmt = $this->_dbh->prepare($query_str . ' LIMIT ?, ?');
>       $stmt->bindParam(1, $limit, PDO::PARAM_INT);
>       $stmt->bindParam(2, $offset, PDO::PARAM_INT);
>                       
>       $stmt->execute();
>                               
>       $records = $stmt->fetchAll(PDO::FETCH_OBJ);
>                                       
>       return $records;                
> }
> 
> 
> 
> Any help will be greatly appreciated.
> 
> 
> Thanks a lot in advance,
> Márcio
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
Solved. Forget to assigning the return value of the method to anything. :S
Sorry.

Márcio

> -----Original Message-----
> From: MEM [mailto:tal...@gmail.com]
> Sent: sábado, 1 de Agosto de 2009 17:13
> To: 'php-gene...@lists.php.net'
> Subject: Newbie: can't access a return value.
> 
> Hi all,
> 
> When I do this:
> $associacao_dao->listar($limit, $offset);
> 
> I can var_dump the correct $limit.
> I can var_dump the correct $offset.
> 
> I CAN'T access the object that I was hoping to get, called $records.
> 
> After this, I was hoping to do var_dump($records); and see the stdClass
> object.
> 
> 
> 
> 
> Here is the listar method:
> 
> public function listar($limit=null, $offset=null)
> {
>       $query_str="SELECT * FROM associacao";
> 
>       $stmt = $this->_dbh->prepare($query_str . ' LIMIT ?, ?');
>       $stmt->bindParam(1, $limit, PDO::PARAM_INT);
>       $stmt->bindParam(2, $offset, PDO::PARAM_INT);
> 
>       $stmt->execute();
> 
>       $records = $stmt->fetchAll(PDO::FETCH_OBJ);
> 
>       return $records;
> }
> 
> 
> 
> Any help will be greatly appreciated.
> 
> 
> Thanks a lot in advance,
> Márcio


--- End Message ---
--- Begin Message ---
A.a.k wrote:

> what if I don't have access to server to enable mod_rewrite like a
> hosting, is there anyway to work around?

No.

> just don't want to build entire website and finally can't get a hosting
> to enable mod_rewrite for me.

Then make it a requirement when you are choosing a (shared) hosting 
provider. 


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: A.a.k [mailto:blue...@gmail.com]
> Sent: Saturday, August 01, 2009 4:13 AM
> To: php-gene...@lists.php.net
> Subject: Re: [PHP] clean url problem .htaccess
> 
> what if I don't have access to server to enable mod_rewrite like a
> hosting,
> is there anyway to work around?
> just don't want to build entire website and finally can't get a hosting
> to
> enable mod_rewrite for me.
> 
> 
> "Andrew Ballard" <aball...@gmail.com> wrote in message
> news:b6023aa40907312352j405778fevd0c38315c3983...@mail.gmail.com...
> On Sat, Aug 1, 2009 at 2:11 AM, A.a.k<blue...@gmail.com> wrote:
> > Hi
> > I'm trying to use clean urls in my application:
> > lets say convert http://mysite/article.php?id=3 to
> > http://mysite/article/3/
> > my problem is to use /article act as it was /article.php
> > here is mt .htacess :
> > <FilesMatch "^article$">
> > ForceType application/x-httpd-php
> > </FilesMatch>
> > on php code parsing string from $_SERVER['PHP_SELF'] to get id out.
> >
> > this one works if i use article.php (http://mysite/article.php/3/
> works)
> > but i want to use /article without php extention. is there a way
> around?
> >
> 
> Look up mod_rewrite.
> 
> Andrew


Have you checked to see if you hosting environment allows custom php.ini files? 
If so, then ask them for information that governs their setup on your server.


Thank you,
Marc Hall
HallMarc Websites
610.446.3346




 

__________ Information from ESET Smart Security, version of virus signature 
database 4296 (20090801) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: O. Lavell [mailto:olav...@xs4all.nl]
> Sent: Saturday, August 01, 2009 12:34 PM
> To: php-gene...@lists.php.net
> Subject: Re: [PHP] clean url problem .htaccess
> 
> A.a.k wrote:
> 
> > what if I don't have access to server to enable mod_rewrite like a
> > hosting, is there anyway to work around?
> 
> No.
> 
> > just don't want to build entire website and finally can't get a
> hosting
> > to enable mod_rewrite for me.
> 
> Then make it a requirement when you are choosing a (shared) hosting
> provider.
> 
> 

 
Meh, there is that! Find a host that has requirements you are looking for. 
Which reminds me... I do allow this in my hosting packages.

Marc Hall
HallMarc Websites
610.446.3346
 

__________ Information from ESET Smart Security, version of virus signature 
database 4296 (20090801) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 


--- End Message ---
--- Begin Message --- On Sat, 01 Aug 2009 01:37:56 +0300, Paul Halliday <paul.halli...@gmail.com> wrote:

Actually, I don't think that regexp's are very slow :)

But I haven't tested them from that perspective.

You should just benchamrk different approaches :)
btw, not sure that substr will help you a lot:

first you have to get a begining of the time, block, then you have to find next X chars.

Btw, you can also do it with a quite simple regexp:
preg_match_all('#\[(.{20})#', ..
(where 20 is amount of characters you want to extract.)
or:
preg_match_all('#\[(.{8})(.{12})#', ..
(where 8 is first part of date, and 12 is second part of date.)

But then you will have to parse this string, to convert it to time, which could take time.

You should just benchmark different approaches, and check which is fastest.

PS: numbers 20,8, 12 are random, just put whtever you need :)
PPS: haven't tested regexps, just check the idea)




I was trying to stay away from regex as much as possible due to the
overhead? I might be wrong here.

This script will be parsing a lot of requests/sec. Thousands, maybe
more, which it also needs to toss into a DB. I want to try and keep it
as fast as possible. This is tricky when you don't know what you are
doing :). My coding is limited to hammering away at the search box on
php.net until I get a push in the right direction. It's just a hack
from there.

Using phpster's substr suggestion has already sped this up considerably.


2009/7/31 Ollisso <olli...@fromru.com>:
On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday <paul.halli...@gmail.com>
wrote:

Whats the cleanest (I have a really ugly) way to break this:

[21/Jul/2009:00:00:47 -0300]

into:

date=21/jul/2009
time=00:00:47

...
Why not just use regexp ?

For example:

$string = "long text.. multiply lines...
       [21/Jul/2009:00:00:47 -0300]

       [ 1/Jul/2009:00:00:47 -0300]

       [22/Jul/2009:00:00:47 -0300]";


preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)
[^]]+\]#',$string,$matches,PREG_SET_ORDER);

print_r($matches);

Output:
Array
(
   [0] => Array
       (
           [0] => [21/Jul/2009:00:00:47 -0300]
           [1] => 21/Jul/2009
           [2] => 00:00:47
       )

   [1] => Array
       (
           [0] => [ 1/Jul/2009:00:00:47 -0300]
           [1] =>  1/Jul/2009
           [2] => 00:00:47
       )

   [2] => Array
       (
           [0] => [22/Jul/2009:00:00:47 -0300]
           [1] => 22/Jul/2009
           [2] => 00:00:47
       )

)


--

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










--- End Message ---
--- Begin Message ---
'Twas brillig, and Miller, Terion at 31/07/09 17:11 did gyre and gimble:
If (ctype_digit($row['critical'])){        echo(" Critical violations found: ". 
$row['critical'] .". ");

Remember that empty() does clever stuff for you.

empty('') == true
empty(0) == true
empty('0') == true
empty(1) == false
empty(2) == false
empty('foo') == false

I suspect you were just being bitten by a misconception of what empty() was supposed to do when you passed certain values to it.

isset() and empty() are subtly different.

Col




--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
Is anyone here interested in discussing programming strategy, or or know of a 
discussion
group which is interested in the subject?

The sorts of questions I am interested in are:

1. I have a highly variable program which always shows the same page, but which 
includes
different modules to give different results.  The various modules call on 
different
functions. Is it better to minimise memory by including only the functions 
actually
required, but increase the number of files included, or to bundle all the 
functions into
one file, thereby reducing the number of files included but increasing the size 
in memory?

2. As PHP is an interpreted program comments certainly increase the memory 
requirements,
and presumably they slow down the operation of the program. Would stripping out 
the
comments before uploading the production version give any visible improvement in
performance?


--- End Message ---
--- Begin Message ---
On Saturday 01 August 2009 8:25:40 pm Clancy wrote:
> Is anyone here interested in discussing programming strategy, or or know of
> a discussion group which is interested in the subject?
>
> The sorts of questions I am interested in are:
>
> 1. I have a highly variable program which always shows the same page, but
> which includes different modules to give different results.  The various
> modules call on different functions. Is it better to minimise memory by
> including only the functions actually required, but increase the number of
> files included, or to bundle all the functions into one file, thereby
> reducing the number of files included but increasing the size in memory?

That depends greatly on your usage patterns.  Does your application make lots 
of "sideways" calls to integrate different modules, or is just "switch on a GET 
parameter, run this function, done"?  If the latter, then lazy-loading just 
the one or two files you want is probably better.  If the former, you'd need a 
lot of interesting logic to make lazy-loading work well enough to be justified. 
 
(I've been working on such a system for Drupal for the past year, and it's not 
easy to get right because there can be a fair bit of overhead.)

If your application is heavily OOP then PHP supports dynamic autoloading of 
classes, which can greatly simplify your code logic but at the same time the 
autoload mechanism itself is not free either.

The age of the computer matters, too.  Modern hard drives are faster than they 
used to be, and more recent OS versions can do some fairly aggressive caching 
if the files you're reading all fit inside the OS cache somewhere in memory so 
you may not actually hit disk to "load" each of your files.

> 2. As PHP is an interpreted program comments certainly increase the memory
> requirements, and presumably they slow down the operation of the program.
> Would stripping out the comments before uploading the production version
> give any visible improvement in performance?

I actually benchmarked that once.  I had a reasonably large PHP file that was, 
in fact, over 50% docblocks.  That's not even counting inline comments.  While 
trying to find things to optimize, removing about 800 lines worth of comments 
(all of the docblocks) did, in fact, produce a noticeable performance 
difference.  It was only barely noticeable, but it just barely registered as 
more than random sampling jitter.  I actually concluded that if cutting the 
file *in half* was only just barely noticeable, then it really wasn't worth the 
effort.

Just install an opcode cache.  That will take care of most of your memory 
issues. :-)

-- 
Larry Garfield
la...@garfieldtech.com

--- End Message ---

Reply via email to