php-general Digest 1 Aug 2009 14:02:19 -0000 Issue 6261

2009-08-01 Thread php-general-digest-help

php-general Digest 1 Aug 2009 14:02:19 - Issue 6261

Topics (messages 296149 through 296163):

Script to Compare Database Structures
296149 by: Matt Neimeyer
296153 by: German Geek
296155 by: Paul M Foster

Re: Can a range be passed to a query?
296150 by: Phpster
296154 by: Paul M Foster
296159 by: Andrew Ballard

Re: Clean break.
296151 by: Ollisso
296152 by: Paul Halliday

Problem: Writing into Files?
296156 by: Parham Doustdar
296161 by: Ollisso

clean url problem .htaccess
296157 by: A.a.k
296160 by: Andrew Ballard
296162 by: A.a.k
296163 by: kranthi

Re: ForEach Range Problems
296158 by: Andrew Ballard

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---
I know I CAN hack something together but I hate to reinvent the wheel.

I want to be able to compare the structure of two different clients
databases that might be on different servers that are firewalled away
from each other. Given the two structures it will list all the SQL
commands needed to make the database structure the same.

In a perfect world on one side you would pull up a PHP page that does
a generate structure which would create a downloadable file which
you could then upload to the other system which would then give a
listing of the SQL commands needed to make the local structure match
the uploaded structure.

Thanks in advance...

Matt
---End Message---
---BeginMessage---
have you tried mysqldiff?

++Tim Hinnerk Heuer++

http://www.ihostnz.com (should be .org)

Sponsors welcome to put ads under a linked to page. This is not automated
just yet. Only image, swf or preferably text or short html ads, no
animations please. Price negotiable.


2009/8/1 Matt Neimeyer m...@neimeyer.org

 I know I CAN hack something together but I hate to reinvent the wheel.

 I want to be able to compare the structure of two different clients
 databases that might be on different servers that are firewalled away
 from each other. Given the two structures it will list all the SQL
 commands needed to make the database structure the same.

 In a perfect world on one side you would pull up a PHP page that does
 a generate structure which would create a downloadable file which
 you could then upload to the other system which would then give a
 listing of the SQL commands needed to make the local structure match
 the uploaded structure.

 Thanks in advance...

 Matt

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


---End Message---
---BeginMessage---
On Fri, Jul 31, 2009 at 05:38:44PM -0400, Matt Neimeyer wrote:

 I know I CAN hack something together but I hate to reinvent the wheel.
 
 I want to be able to compare the structure of two different clients
 databases that might be on different servers that are firewalled away
 from each other. Given the two structures it will list all the SQL
 commands needed to make the database structure the same.
 
 In a perfect world on one side you would pull up a PHP page that does
 a generate structure which would create a downloadable file which
 you could then upload to the other system which would then give a
 listing of the SQL commands needed to make the local structure match
 the uploaded structure.
 
 Thanks in advance...

I don't know what flavor of SQL you're using, but for SQL-compliant
databases, there is an information_schema table (I believe that's the
correct name) which contains most or all of the data you need. Query
that table into an array for each server, and compare the arrays.

Here's a query I've used:

SELECT table_name, column_name, data_type, column_default, is_nullable,
character_maximum_length, numeric_precision, numeric_scale FROM
information_schema.columns WHERE table_name = 'tablename' ORDER BY
ordinal_position

This will not tell you the relations between tables, nor which columns
are primary keys, etc. There may be another way to get this out of
information_schema.

Paul

--
Paul M. Foster
---End Message---
---BeginMessage---





On Jul 31, 2009, at 5:24 PM, Miller, Terion tmil...@springfi.gannett.com 
 wrote:


I'm still struggling with using ranges... Can they be passed to a  
query

somehow...

I have this so far but it pulls nothing:

//Show all  with $letter  not between A and Z

if ($

$result = mysql_query($sql) or die(mysql_error());

}

while($row = mysql_fetch_assoc($result)){



$name = $row['name'];

printf(

'a href=view.php?ID=%sb%s/bbr /%sbr /br //a',

$row['ID'],

$row['name'],

$row['address']

);


}


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

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

2009-08-01 Thread php-general-digest-help
 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.kblue...@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---
---BeginMessage---
 -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---
---BeginMessage---
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---
---BeginMessage---

'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

[PHP] clean url problem .htaccess

2009-08-01 Thread A.a.k

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? 



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



Re: [PHP] ForEach Range Problems

2009-08-01 Thread Andrew Ballard
On Fri, Jul 31, 2009 at 4:51 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:
 //Show all restaurants that start with $letter not
 between A and Z

 $other = ctype_digit($letter);

 foreach(range('0','9') as $other) {

 $sql = SELECT  DISTINCT ID, name, address
 FROMrestaurants
 WHERE   name LIKE '{$other}%' ;

 $result = mysql_query($sql) or die(mysql_error());

 while($row = mysql_fetch_assoc($result)){

 $name = $row['name'];

 printf(
 'a href=view.php?ID=%sb%s/bbr /%s'
 . 'br /br //a',
 $row['ID'],
 $row['name'],
 $row['address']
 );
 }
 }


Why are you running 10 individual queries to search for restaurants
whose name begins with a number?

There are (at least) two simple, sargable alternatives available that
will work in MySQL to do the work in one shot:

SELECT  DISTINCT ID, name, address
FROMrestaurants
WHERE   name LIKE '0%'
   OR   name LIKE '1%'
   OR   name LIKE '2%'
   OR   name LIKE '3%'
   OR   name LIKE '4%'
   OR   name LIKE '5%'
   OR   name LIKE '6%'
   OR   name LIKE '7%'
   OR   name LIKE '8%'
   OR   name LIKE '9%'

(It can use an index on the `name` column and it works, but it's
pretty verbose. Performance might suffer a little if it involves a
table scan because of the OR's, but I'm not sure about that.)

SELECT  DISTINCT ID, name, address
FROMrestaurants
WHERE   name = '0' AND name  'A';

(Its a lot shorter because it takes advantage of string collation. Any
string that begins with the character '0' will be greater than (or
equal if the string is exactly '0') than '0'.)


Also, if your table is set up correctly, you do not need the DISTINCT
keyword in your query. Each restaurant should appear exactly once in
the `restaurants` table.

And just for fun... do you have any restaurants in your list whose
name begins with a punctuation mark or some other non-alphanumeric
character?  :-)


Andrew

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



Re: [PHP] Can a range be passed to a query?

2009-08-01 Thread Andrew Ballard
On Fri, Jul 31, 2009 at 5:55 PM, Phpsterphps...@gmail.com wrote:
 What about

 $sql = SELECT DISTINCT ID, name, address FROM restaurants WHERE
 left(name, 1) between 0 and 9;




 Bastien

 Sent from my iPod

You need to wrap the 0 and the 9 in single quotes, or else it returns
everything.

$sql = SELECT DISTINCT ID, name, address FROM restaurants WHERE
 left(name, 1) between '0' and '9';

Performance could be an issue, also. I tried this and the two versions
I posted on her other thread against a table I have that has just over
8700 rows in it. This version took over 9 times longer to execute.
(Granted, on a table that small it's still 0.0092 seconds compared to
0.0010 seconds. Either of those times is acceptable in my book, but on
a larger table a 9x performance drain could be a serious issue.)
That's because the engine has to examine every row in the table and
calculate left(name, 1) before it can compare that value to the range.
The other versions I posted can simply scan/seek the index within a
range.

Andrew

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



Re: [PHP] clean url problem .htaccess

2009-08-01 Thread Andrew Ballard
On Sat, Aug 1, 2009 at 2:11 AM, A.a.kblue...@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

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



[PHP] Re: Problem: Writing into Files?

2009-08-01 Thread Ollisso
On Sat, 01 Aug 2009 08:20:23 +0300, Parham Doustdar parha...@gmail.com  
wrote:



Hi there,
I've written a counter for my blog, which keeps the count of visitors in  
a file. However, when the visitors get too many, it resets to zero. Why?


Here's the piece of code:

[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, r);
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, w);
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]

I'm thinking this is caused by two visitors visiting the page at the  
same time; but is there a way to fix it, perhaps the reading/writing  
parameter?


Thanks!



Check:
http://www.php.net/flock


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] clean url problem .htaccess

2009-08-01 Thread A.a.k
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.kblue...@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 



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



Re: [PHP] clean url problem .htaccess

2009-08-01 Thread kranthi
mod_rewrite is the best solution available to your case. more over if
you are sure that your host supports .htaccess, there is very little
chance that they will block mod rewrite alone. you can confirm that by
phpinfo. look in apache2handler- Loaded Modules  section (this does
not tell you if .htaccess is enabled/disabled)

but in the worst case try using $_SERVER['REQUEST_URI'] instead of
$_SERVER['PHP_SELF'].

in either case you cannot do this with .htaccess disabled.

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



[PHP] Newbie: can't access a return value.

2009-08-01 Thread MEM
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



Re: [PHP] clean url problem .htaccess

2009-08-01 Thread O. Lavell
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. 


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



Re: [PHP] Newbie: can't access a return value.

2009-08-01 Thread TG
Try:

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

-TG

- Original Message -
From: MEM tal...@gmail.com
To: php-general@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
 


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



[PHP] RE: Newbie: can't access a return value.

2009-08-01 Thread MEM
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-general@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


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



Re: [PHP] Re: Clean break.

2009-08-01 Thread ollisso
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












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



[PHP] Re: 2 ifs embedded? (RESOLVED)

2009-08-01 Thread Colin Guthrie

'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/]


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



RE: [PHP] clean url problem .htaccess

2009-08-01 Thread HallMarc Websites
 -Original Message-
 From: A.a.k [mailto:blue...@gmail.com]
 Sent: Saturday, August 01, 2009 4:13 AM
 To: php-general@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.kblue...@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
 


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



RE: [PHP] clean url problem .htaccess

2009-08-01 Thread HallMarc Websites
 -Original Message-
 From: O. Lavell [mailto:olav...@xs4all.nl]
 Sent: Saturday, August 01, 2009 12:34 PM
 To: php-general@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
 


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



[PHP] PHP programming strategy

2009-08-01 Thread Clancy
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?


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



Re: [PHP] PHP programming strategy

2009-08-01 Thread Larry Garfield
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

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



Re: [PHP] PHP programming strategy

2009-08-01 Thread Eddie Drapkin
 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.

Yeah but what happens if you run the script through the tokenizer and
strip ALL comments, unnecessary whitespace, newline characters, etc.
out?

 Larry Garfield
 la...@garfieldtech.com

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



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



[PHP] Re: Problem: Writing into Files?

2009-08-01 Thread Parham Doustdar
Dear Ollisso,
I tried it with FLock() but it still didn't work. This is what I did:
[code]
$fp = fopen($f, r);
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, w);
while (!flock($fw, LOCK_EX))
sleep(1);
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
flock($fw, LOCK_UN);
fclose($fw);
[/code]

Am I doing anything wrong here?
Thanks!
-- 
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
Ollisso olli...@fromru.com wrote in message 
news:op.uxy29woc48v...@ol-n.kyla.fi...
 On Sat, 01 Aug 2009 08:20:23 +0300, Parham Doustdar parha...@gmail.com 
 wrote:

 Hi there,
 I've written a counter for my blog, which keeps the count of visitors in 
 a file. However, when the visitors get too many, it resets to zero. Why?

 Here's the piece of code:

 [code]
 $f = $dir . '/view_counter' .EXT;
 $fp = fopen($f, r);
 $count =fgets($fp, 1024);
 fclose($fp);
 $fw = fopen($f, w);
 $cnew = $count + 1;
 $countnew = fputs($fw, $count + 1);
 return $cnew;
 [/code]

 I'm thinking this is caused by two visitors visiting the page at the 
 same time; but is there a way to fix it, perhaps the reading/writing 
 parameter?

 Thanks!


 Check:
 http://www.php.net/flock


 -- 
 Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ 



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



Re: [PHP] PHP programming strategy

2009-08-01 Thread Paul M Foster
On Sun, Aug 02, 2009 at 11:25:40AM +1000, 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?

My advice would be to only load the modules you need, no matter how
convoluted the logic you must use to do that. A lot of PHP programmers
are very sloppy about memory usage, falling back on the cache argument,
etc. But there's no reason to use more memory than you have to.

However, there is an issue if all these modules are scattered about
everywhere. You also have to look at the overhead on the server when
it's having to open 15 files for every page displayed. That's silly as
well.

So it's a trade-off. If you have the latter problem, I'd probably opt to
put everything in one or a few files. In my opinion, disk thrashing on a
busy internet server is worse than gobbling up more memory. That disk
thrashing is likely to have a negative effect on all the other users of
that server.

 
 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 bow to those who have profiled this, as far as performance goes.
However, remember, you have to *maintain* this code. In a trade-off
between performance and maintainability, I'd opt for maintainability.
You'll thank yourself in the future.

Paul


-- 
Paul M. Foster

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