Re: [PHP] Re: set up mass virtual hosting with apache/nginx and PHP ... best practice2012?

2012-08-25 Thread D. Dante Lorenso

On 8/25/12 6:11 AM, Matijn Woudt wrote:

Hi Dante,

Wouldn't it be much easier to use reseller packages like DirectAdmin
or cPanel? AFAIK it should be pretty easy to do the things above.


I'm considering that as well.  In the end, I really only want 3 
features, however:


 - ftp access to files
 - mysql database
 - apache/php support

Look at DirectAdmin features:
http://www.directadmin.com/features.html

Looks like 80-90% of that is not needed.  I want to manage my users 
through Active Directory, and just enable or disable the 3 services I 
listed above.


I recently tested ISP Manager.  Their trial license couldn't even be 
installed without a public IP address!  I don't want to get into these 
games.  Just some simple, clean, open source solutions, please :-)


Also, I intend to make this solution scalable.  I have 2 HA load 
balancers that will distribute the web load across multiple web servers. 
 Licensing starts to get expensive when you begin to think clusters or 
clouds.  I want to scale without additional licensing costs.


I'll install DirectAdmin and cPanel now that you recommend them, 
however, to make sure I don't actually want them :-)


-- Dante


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



Re: [PHP] set up mass virtual hosting with apache/nginx and PHP ... best practice 2012?

2012-08-25 Thread D. Dante Lorenso

On 8/25/12 7:50 AM, Duken Marga wrote:

 From my experience to maintain many virtual host, I prefer use Apache
+ PHP + suPHP. I think this combination will be able to cover your ideal
situation above. But, I usually use authentication via shell user
(/etc/user). You must find tutorial or something that integrate Apache
and Active Directory (there are many out there).

suPHP is designed to replace suExec (default Apache mod). It will run a
PHP file as a user that own the files. There are no problem if you want
to use it for many user, because suPHP is designed for that. For user
who will uploade file, you can always use FTP to access their own file.
Each user can has their own .htaccess in their own directory and all the
websites will have one global rule in httpd.conf.


Using VirtualDocumentRoot, I was able to create a virtual host defined 
like this:


VirtualHost *:80
ServerName student.sampledomain.edu
ServerAlias *.student.sampledomain.edu

DocumentRoot /mnt/web/student.sampledomain.edu/docroot
UseCanonicalName Off
VirtualDocumentRoot /mnt/userwww/%-4+

ErrorLog |/usr/bin/logger -p local6.notice -t 'error-student'
CustomLog |/usr/bin/logger -p local6.notice -t 'access-student' full
/VirtualHost

That maps domain names like username.student.sampledomain.edu to 
directories in the /mnt/userwww/username directory.  That gets me 
close, but isn't handling PHP yet.  I think Apache also runs as 'apache' 
user when reading all the files, so users must chmod their files world 
readable still for this to work.


You reference suPHP as the way to go.  The problem I have with that is 
this website:

http://www.suphp.org/Home.html

Looks like the last update was back in 2009.  That's more than 3 years 
ago.  I think that project has stalled.  There must be something newer 
that has replaced it since then.


-- Dante




On Wed, Aug 22, 2012 at 6:26 AM, D. Dante Lorenso da...@lorenso.com
mailto:da...@lorenso.com wrote:

All,

I need to set up a server to enable 5,000 students to have web
hosting provided by the school with PHP and MySQL support.  I'm
trying to figure out what is the best way to do this.

We have Active Directory and are using Centrify to authenticate
usernames and passwords on our Linux servers.  I am imagining it
would be great if we use something like ExecCGI to ensure that PHP
runs as the user that owns the files.  We would then provide FTP
access to the files and FTP would authenticate against Active
Directory making sure to set the proper user/group on files when
uploaded.

I see that PHP-FPM exists: http://php-fpm.org  and it claims
Ability to start workers with different uid/gid/chroot/environment
and different php.ini (replaces safe_mode) which is exactly what
I'm looking for.  It also claims PHP-FPM is now included in PHP
core as of PHP 5.3.3. so that's good.

I also read about the greatness that is NGinX: http://nginx.org
though I don't know if I can use it because I think I also need to
use .htaccess files.  I need a way for students to be able to
password protect their directories and files.  If there's another
way using NGinX or Apache, that's good too.  I know of no other way.

Here is an interesting article from 2009:

http://www.howtoforge.com/how-__to-set-up-mass-virtualhosting-__with-apache2-mod_rewrite-mod___userdir-mod_suexec-on-centos-__5.3

http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3

That uses mod_rewrite to attempt something like what I'm trying to
do ... and then, Apache has mod_vhost_alias:
http://httpd.apache.org/docs/__2.2/mod/mod_vhost_alias.html
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

So, I see a lot of information out there.  Apache, NginX, ExecCGI,
FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I
suspect some of these methods are old and out of date.

In my ideal situation:

  - users would be created in AD and would exist on the OS

  - student domain names would look like:
 http://username.student.__school.edu/
http://student.school.edu/ - OR -
http://student.school.edu/__username/

  - file directories would look like:
 /mnt/somedir/username/__docroot

  - students would be able to create PHP applications executed with
 their own permissions

  - I would be able to configure all 5,000 accounts with a single
 configuration (1 virtual host rule?)

Do you know what the best practices are for now ... here in 2012?

-- Dante


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




--
Duken Marga




-- Dante

D. Dante Lorenso


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



[PHP] set up mass virtual hosting with apache/nginx and PHP ... best practice 2012?

2012-08-21 Thread D. Dante Lorenso

All,

I need to set up a server to enable 5,000 students to have web hosting 
provided by the school with PHP and MySQL support.  I'm trying to figure 
out what is the best way to do this.


We have Active Directory and are using Centrify to authenticate 
usernames and passwords on our Linux servers.  I am imagining it would 
be great if we use something like ExecCGI to ensure that PHP runs as the 
user that owns the files.  We would then provide FTP access to the files 
and FTP would authenticate against Active Directory making sure to set 
the proper user/group on files when uploaded.


I see that PHP-FPM exists: http://php-fpm.org  and it claims Ability to 
start workers with different uid/gid/chroot/environment and different 
php.ini (replaces safe_mode) which is exactly what I'm looking for.  It 
also claims PHP-FPM is now included in PHP core as of PHP 5.3.3. so 
that's good.


I also read about the greatness that is NGinX: http://nginx.org though I 
don't know if I can use it because I think I also need to use .htaccess 
files.  I need a way for students to be able to password protect their 
directories and files.  If there's another way using NGinX or Apache, 
that's good too.  I know of no other way.


Here is an interesting article from 2009:
http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3

That uses mod_rewrite to attempt something like what I'm trying to do 
... and then, Apache has mod_vhost_alias:

http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

So, I see a lot of information out there.  Apache, NginX, ExecCGI, 
FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I suspect 
some of these methods are old and out of date.


In my ideal situation:

 - users would be created in AD and would exist on the OS

 - student domain names would look like:
http://username.student.school.edu/ - OR -
http://student.school.edu/username/

 - file directories would look like:
/mnt/somedir/username/docroot

 - students would be able to create PHP applications executed with
their own permissions

 - I would be able to configure all 5,000 accounts with a single
configuration (1 virtual host rule?)

Do you know what the best practices are for now ... here in 2012?

-- Dante


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



[PHP] php safe mode no more?

2012-08-02 Thread D. Dante Lorenso
The school I work with wants to set up PHP and MySQL hosting for about 
10,000 students.


I see that in 5.4, PHP safe-mode is being removed.  How is it supposed 
to be done if not safe-mode?


Are all the hosting providers using suExec and running PHP as CGI or 
FastCGI?  If I'm trying to do this the right way, what way is that? 
Anyone got link or pointers on what I need to learn?


-- Dante


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



Re: [PHP] Serving a .dmg via readfile?

2012-04-25 Thread D. Dante Lorenso

On 4/25/12 10:54 PM, Brian Dunning wrote:

Hey all - I'm having no luck serving a .dmg from my online store. I stripped 
down the code to just the following to debug, but no matter what I get a 
zero-byte file served:

   header('Content-Type: application/x-apple-diskimage');   // also tried 
octet-stream
   header('Content-Disposition: attachment; filename=My Cool Image.dmg');
   $size = filesize('/var/www/mypath/My Cool Image.dmg');
   header('Content-Length: '.$size);
   readfile('/var/www/mypath/My Cool Image.dmg');

This same code works for a number of other file types that I serve: bin, zip, 
pdf. Any suggestions? Professor Google is not my friend.


Most likely your file is larger than the memory you have available to 
PHP.  The readfile() command will load the whole file into memory before 
streaming it out.


You'll want to use fopen, fread, fwrite, and fclose to loop through 
bytes in your file as you shuttle chunks to the client instead of 
slooping it all into memory in one hunk.


-- Dante

D. Dante Lorenso
da...@lorenso.com

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



[PHP] is there a static constructor?

2011-03-30 Thread D. Dante Lorenso

All,

I want to build a config file class that gets called statically.  Is 
there such a thing as a static constructor?  Example:


class Daz_Config {
  public static function load() {
...
  }
  public static function get($key) {
self :: load();
...
  }
}

Daz_Config :: get('myvalue');

I want to call the load function when the class is used for the first 
time.  If no code ever calls Daz_Config :: get(...) then I never want 
to invoke load() but if it does get called, I only want to call load() 
once before the class is used further.


Anyone know how to do this with calling load() at the top of all the 
other functions and writing a load() function that exits early if 
already loaded?


-- Dante

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



Re: [PHP] Path question

2011-03-29 Thread D. Dante Lorenso

On 3/28/11 8:18 PM, Jack wrote:

Hello All,
Is there a smarter way to do includes by setting up a path or something
where I don't have to include /home/domain.com/includes/include_file.php
Apparently my path is as shown above,  but I would prefer to just put in
/includes/include_file.php


I wrote about this a long time ago ... perhaps it might help:

http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/

Talks about putting your functions into classes and using the autoloader 
to avoid putting include statements in your code.


Might not help if you are loading content which is not just PHP 
functions/code, but if you haven't evolved this far yet, the read 
might help you out.


-- Dante

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



Re: [PHP] Howdy (new in here)

2011-02-18 Thread D. Dante Lorenso

On 2/18/11 8:39 AM, Kirk Bailey wrote:

Oh hey, that's a good point. All the stuff i saw so far indented 2
spaces. WHY?
Can I just indent a TAB if my editor permits this? indenting 4 spaces (2
nests) is easy, but suppose I hit one extra space- not enough difference
to be really noticeable. Let's talk about indentation in php for a
moment, could we?


I use PHPEclipse for an editor.  It has the best code beautifier I've 
used for PHP class editing.  I hit Ctrl+Shift+F and the whole file jumps 
into the format I have predefined.  It handles indentation, curly braces 
up or down, spacing, etc.


I can take code snippets from anywhere and with a couple keystrokes, the 
format adheres to my preferences and is readable.


-- Dante





On 2/16/2011 6:36 PM, Tamara Temple wrote:


On Feb 15, 2011, at 11:23 PM, Brian Waters wrote:


On Tue, Feb 15, 2011 at 11:46 PM, Tamara Temple
tamouse.li...@gmail.com wrote:


I was unlucky enough to find someone who coded a
function that went on for 30 pages one (this was in C, not PHP) and
*that*
was hard to untangle.


Why!?!?!?!?!?!?!

- BW


(un?)fortunately, he was no longer with the company, which was why I
got to take it over. It wasn't the oddest thing, by far. His designs
were hugely complex (way overengineered for the task at hand, plus
they didn't work), and he didn't use any consistent indenting style.


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



Re: [PHP] Re: String manipulation

2010-11-14 Thread D. Dante Lorenso

On 11/14/10 2:48 PM, Ron Piggott wrote:

How would I write an IF statement that looks for the first space space (“ “) left of 
the 76th character in a string orbr, which ever comes first --- OR the end of 
the string (IE the string is less than 76 characters long? I specifically want is 
it’s character position in the string.  Ron


... but you sound like you are looking for the 'wordwrap' function.

-- Dante

--
D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



Re: [PHP] Template engines

2010-11-11 Thread D. Dante Lorenso

On 11/11/10 12:04 PM, Michael Shadle wrote:
 Not to discredit this long post but the media here is now calling
 kids who text often hypertexting teens which really irked me
 even more...I bet some non-technical news guy thinks he is
 awesome for coming up with that one.

LOL!  I too thought those kids were going around creating HTML pages 
with their phones!


-- Dante

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



Re: [PHP] auto indentation

2010-04-27 Thread D. Dante Lorenso

On 4/27/2010 3:55 PM, Ashley Sheridan wrote:

On Tue, 2010-04-27 at 16:33 -0400, David McGlone wrote:

Hi everyone.
I got a quickie LOL
is there a way to auto indent code. I'm using Kate and I have it set so the
tab is only 4 spaces, but I was wondering if there was an easier way than to
have to hit the tab key 1x then 2x then 3x then 2x then 1x to create nice laid
out code like this:


I use PHPEclipse for this.  It's not Eclipse with PDT, it's PHP Eclipse:

http://www.phpeclipse.com/

The code formatter built into that formats my code when I hit 
Ctrl+Shift+F.  No other code formatter works as well for what I've 
found.  Many formatters just indent, this one will reformatt by putting 
brackets up or down, and reindent all the code to fit my coding standards.


Project is getting a little old, though and doesn't yet support PHP 5.3 
syntax, but it's still the best I've found.


-- Dante

--
D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



[PHP] Example of good PHP namespace usage?

2010-03-19 Thread D. Dante Lorenso

All,

I want to start using PHP namespaces for my projects.  Currently, I name 
my classes similar to how Zend Framework names theirs and I end up with 
classes like:


  LS_Util_String

I'm thinking that if I converted this to namespaces, the classes would 
be named like:


  LS\Util\String

I'd like to look at an example of an open source project that has 
already adopted namespaces as the way to do it and would be a good 
best practices case for how I should go about setting up my library 
namespaces.


I have been playing with concepts of using a Java-like naming convention 
for classes and have created my own namespace like:


com\larkspark\util\String

And here I was thinking that packages would be lowercase and classes 
would be camelcase with initial caps.


I'm getting ready to build a new project and wanted to do it in the 
future-forward style while removing legacy classes and refactoring 
everything to use namespaces.


Any examples out there?  Everything I find from searching Google is 
novice intro to PHP namespaces blogs, but nothing concrete.  Also since 
namespaces are relatively new, I see a lot of misleading guides where 
they are using :: instead of \ to separate class name parts.  What 
does this list recommend?


Dante

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



Re: [PHP] memory efficient hash table extension? like lchash ...

2010-01-25 Thread D. Dante Lorenso

J Ravi Menon wrote:

PHP does expose sys V shared-memory apis (shm_* functions):
http://us2.php.net/manual/en/book.sem.php



I will look into this.  I really need a key/value map, though and would 
rather not have to write my own on top of SHM.




If you already have apc installed, you could also try:
http://us2.php.net/manual/en/book.apc.php
APC also allows you to store user specific data too (it will be in a
shared memory).



I've looked into the apc_store and apc_fetch routines:
http://php.net/manual/en/function.apc-store.php
http://www.php.net/manual/en/function.apc-fetch.php
... but quickly ran out of memory for APC and though I figured out how 
to configure it to use more (adjust shared memory allotment), there were 
other problems.  I ran into issues with logs complaining about cache 
slamming and other known bugs with APC version 3.1.3p1.  Also, after 
several million values were stored, the APC storage began to slow down 
*dramatically*.  I wasn't certain if APC was using only RAM or was 
possibly also writing to disk.  Performance tanked so quickly that I set 
it aside as an option and moved on.




Haven't tried these myself, so I would do some quick tests to ensure
if they meet your performance requirements. In theory, it should be
faster than berkeley-db like solutions (which is also another option
but it seems something similar like MongoDB was not good enough?).



I will run more tests against MongoDB.  Initially I tried to use it to 
store everything.  If I only store my indexes, it might fare better. 
Certainly, though, running queries and updates against a remote server 
will always be slower than doing the lookups locally in ram.




I  am curious to know if someone here has run these tests. Note that
with memcached installed locally (on the same box running php), it can
be surprisingly efficient - using pconnect(),  caching the handler in
a static var for a given request cycle etc...


memcached gives no guarantee about data persistence.  I need to have a 
hash table that will contain all the values I set.  They don't need to 
survive a server shutdown (don't need to be written to disk), but I can 
not afford for the server to throw away values that don't fit into 
memory.  If there is a way to configure memcached guarantee storage, 
that might work.


-- Dante



On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso da...@lorenso.com wrote:

shiplu wrote:

On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso da...@lorenso.com
wrote:

All,

I'm loading millions of records into a backend PHP cli script that I
need to build a hash index from to optimize key lookups for data that
I'm importing into a MySQL database.  The problem is that storing this
data in a PHP array is not very memory efficient and my millions of
records are consuming about 4-6 GB of ram.


What are you storing? An array of row objects??
In that case storing only the row id is will reduce the memory.

I am querying a MySQL database which contains 40 million records and mapping
string columns to numeric ids.  You might consider it normalizing the data.

Then, I am importing a new 40 million records and comparing the new values
to the old values.  Where the value matches, I update records, but where
they do not match, I insert new records, and finally I go back and delete
old records.  So, the net result is that I have a database with 40 million
records that I need to sync on a daily basis.


If you are loading full row objects, it will take a lot of memory.
But if you just load the row id values, it will significantly decrease
the memory amount.

For what I am trying to do, I just need to map a string value (32 bytes) to
a bigint value (8 bytes) in a fast-lookup hash.


Besides, You can load row ids in a chunk by chunk basis. if you have
10 millions of rows to process. load 1 rows as a chunk. process
them then load the next chunk.  This will significantly reduce memory
usage.

When importing the fresh 40 million records, I need to compare each record
with 4 different indexes that will map the record to existing other records,
or into a group_id that the record also belongs to.  My current solution
uses a trigger in MySQL that will do the lookups inside MySQL, but this is
extremely slow.  Pre-loading the mysql indexes into PHP ram and processing
that was is thousands of times faster.

I just need an efficient way to hold my hash tables in PHP ram.  PHP arrays
are very fast, but like my original post says, they consume way too much
ram.


A good algorithm can solve your problem anytime. ;-)

It takes about 5-10 minutes to build my hash indexes in PHP ram currently
which makes up for the 10,000 x speedup on key lookups that I get later on.
 I just want to not use the whole 6 GB of ram to do this.   I need an
efficient hashing API that supports something like:

   $value = (int) fasthash_get((string) $key);
   $exists = (bool) fasthash_exists((string) $key);
   fasthash_set((string) $key, (int) $value

Re: [PHP] memory efficient hash table extension? like lchash ...

2010-01-24 Thread D. Dante Lorenso

shiplu wrote:

On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso da...@lorenso.com wrote:

All,

I'm loading millions of records into a backend PHP cli script that I
need to build a hash index from to optimize key lookups for data that
I'm importing into a MySQL database.  The problem is that storing this
data in a PHP array is not very memory efficient and my millions of
records are consuming about 4-6 GB of ram.



What are you storing? An array of row objects??
In that case storing only the row id is will reduce the memory.


I am querying a MySQL database which contains 40 million records and 
mapping string columns to numeric ids.  You might consider it 
normalizing the data.


Then, I am importing a new 40 million records and comparing the new 
values to the old values.  Where the value matches, I update records, 
but where they do not match, I insert new records, and finally I go back 
and delete old records.  So, the net result is that I have a database 
with 40 million records that I need to sync on a daily basis.



If you are loading full row objects, it will take a lot of memory.
But if you just load the row id values, it will significantly decrease
the memory amount.


For what I am trying to do, I just need to map a string value (32 bytes) 
to a bigint value (8 bytes) in a fast-lookup hash.



Besides, You can load row ids in a chunk by chunk basis. if you have
10 millions of rows to process. load 1 rows as a chunk. process
them then load the next chunk.  This will significantly reduce memory
usage.


When importing the fresh 40 million records, I need to compare each 
record with 4 different indexes that will map the record to existing 
other records, or into a group_id that the record also belongs to.  My 
current solution uses a trigger in MySQL that will do the lookups inside 
MySQL, but this is extremely slow.  Pre-loading the mysql indexes into 
PHP ram and processing that was is thousands of times faster.


I just need an efficient way to hold my hash tables in PHP ram.  PHP 
arrays are very fast, but like my original post says, they consume way 
too much ram.



A good algorithm can solve your problem anytime. ;-)


It takes about 5-10 minutes to build my hash indexes in PHP ram 
currently which makes up for the 10,000 x speedup on key lookups that I 
get later on.  I just want to not use the whole 6 GB of ram to do this. 
   I need an efficient hashing API that supports something like:


$value = (int) fasthash_get((string) $key);
$exists = (bool) fasthash_exists((string) $key);
fasthash_set((string) $key, (int) $value);

Or ... it feels like a memcached api but where the data is stored 
locally instead of accessed via a network.  So this is how my search led 
me to what appears to be a dead lchash extension.


-- Dante

--
D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



[PHP] memory efficient hash table extension? like lchash ...

2010-01-23 Thread D. Dante Lorenso

All,

I'm loading millions of records into a backend PHP cli script that I
need to build a hash index from to optimize key lookups for data that
I'm importing into a MySQL database.  The problem is that storing this
data in a PHP array is not very memory efficient and my millions of
records are consuming about 4-6 GB of ram.

I have tried using some external key/value storage solutions like
MemcacheDB, MongoDB, and straight MySQL, but none of these are fast
enough for what I'm trying to do.

Then I found the lchash extension for PHP and it looks like exactly
what I want.  It's a c-lib hash which is accessed from PHP.  Using it
would be slightly slower than using straight PHP arrays, but would be
much more memory efficient since not all data needs to be stored as PHP
zvals, etc.

Problem is that the lchash extension can't ben installed in my PHP 5.3 
build because pecl install lchash fails with a message about invalid 
checksum on the README file.  Apparently this extension has been 
neglected and abandoned and hasn't been updated since 2005.


Is there something like lchash that *is* being maintained?  What would 
you all suggest?


-- Dante


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



Re: [PHP] Better way of doing this? (menu and submenus)

2006-06-21 Thread D. Dante Lorenso
If you are using PostgreSQL, there is a 'connectby' function (part of 
contrib) which will recursively join hierarchical data where you have 
PID -- ID recursive joins.  Oracle also has CONNECT BY built into the 
SQL language.  I do not know if MySQL natively supports anything similar 
but maybe someone on this list knows the answer to that.


Having a CONNECT BY clause avoids having to do round trip selects for 
each of your sub categories and greatly simplifies queries, IMHO.


Dante


Mark Steudel wrote:
You could use a recursive function and keep it all in one table. 


My Table is similar to the one below:

ID  NAMEPID DISPLAY_ORDER

Here's crude recursive function to display this in a list typical of what
you used to style a menu. The great thing about this is that you could have
unlimited submenus if you wanted ...

function displayMenu( $pid )
{
global $db;

$res = $db-query( SELECT * FROM tblmenu WHERE pid = '.$pid.'
ORDER BY display_order );
mysqlErrorCheck( $res );

while( $res-fetchInto( $objData ) )
{
$html .= li.$objData['name'];
$html .= ul.displayMenu( $objData['id'] )./ul;
$html .= /li;
}

return $html;
}


echo ul.displayMenu('0')./ul;


-Original Message-
From: Ryan A [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 21, 2006 10:51 AM

To: Philip Thompson; php-general@lists.php.net
Subject: Re: [PHP] Better way of doing this? (menu and submenus)


  

Ryan,

I have run into a similar problem with one of the
sites I'm designing.  
Here's the approach I took. You can see if it fits

your needs.

Here's an example of  
what I have:


MID  NAMEPARENT_ID  LOCATION
1Homenull index.php
2Productsnull products.php
3Information null info.php
10   Profile 1  profile.php
11   Account 1  account.php
20   Hardware2  hardware.php
21   Software2  software.php
210  M$ Word 21 msword.php
211  iLife   21 ilife.php

And I think you get the drift. 
You can keep getting deeper in the  
tree structure and not have to worry about adding

more tables.

Notice that the menu_item_id (MID) actually has some
organization to  
it, but this is completely optional. As the menu
items grow, this will  
probably be more difficult to keep track of. Anyway,

hope that helps!





@Phillip,
Thanks for replying.

Because (like you pointed out) the MID can get a
little crazy I was thinking of using two tables, one
for parent and the other for the children.

Also, I forgot to mention in my first post, I am using
a p_position (parent position) and c_position (child)
for each of the menu items, that way I can do a ORDER
BY in my query and it should still look good and
changing positions shouldnt be a problem (ask anyone
who's married, being flexable in changing positions is
VERY important :-D )
Doing an ORDER BY on two tables in also a bit more
simple than one (IMHO, feel free to correct me)

I really appreciate your input on this as I am in the
theory stage while you have actually made something
like this, thanks again.



@K. Bear - Thanks for the link, I'll check it out as
soon as i get a little time.

Cheers!
Ryan




--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

  


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



Re: [PHP] For Loop

2006-06-20 Thread D. Dante Lorenso

Albert Padley wrote:
Thanks everyone. Always nice to know there is more than one direction 
to go in.


A alternative to variable variables might use these:

   http://us3.php.net/manual/en/function.compact.php
   http://us3.php.net/manual/en/function.extract.php

'extract' looks like it might be right up your alley:

   ?php
   $vars = array();
   for ($i=1; $i100; $i++) { $vars[p.$i.name] = $i; }
   extract($vars);
   ?

Dante



On Tuesday 20 June 2006 15:14, Albert Padley wrote:

I have a regular for loop - for($i=1; $i100; $i++)

Within the loop I need to create variables named:

$p1name;
$p2name;
$p3name;
etc.

The integer portion of each variable name needs to be the value of 
$i.


I can't seem to get my syntax correct?

Can someone point me in the right direction?

Thanks.

Albert Padley


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



Re: [PHP] basic php problem

2006-06-15 Thread D. Dante Lorenso

Dave Goodchild wrote:

if $_REQUEST['page'] is not set, why not do this:
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
(ternary operator)


// test, numeric read, with default and bounds checking
$page = empty($_REQUEST['page']) ? 1 : intval($_REQUEST['page']);
$page = min(max($page, 1), $MAX_PAGE);

Dante

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



[PHP] paging results in large resultsets: mysql vs postgresql?

2006-06-15 Thread D. Dante Lorenso

All,

I just discovered this neat little gem in MySQL which makes it easy to 
page large result sets:


   * SELECT SQL_CALC_FOUND_ROWS *
 FROM table
 LIMIT 10, 10

   * SELECT FOUND_ROWS()

The neat thing is that SQL_CALC_FOUND_ROWS will cause MySQL to tally up 
all the rows that WOULD have matched your query if you hadn't used the 
LIMIT and OFFSET clause to shorten your returned results.  The next call 
to FOUND_ROWS() will return that tally. 

When developing paged list/search results this is VERY powerful 
shorthand for generating the prev/next links and figuring out how many 
pages to display.


I can't seem to find the equivalent of it in PostgreSQL!  The only 
options I see are:


  1.

 TWO queries.  The first query will perform a SELECT COUNT(*) ...; and the 
second query performs the actualy SELECT ... LIMIT x OFFSET y;


  2.

 Using PHP row seek and only selecting the number of rows I need.

Here is an example of method number 2 in PHP:

?php
//--
function query_assoc_paged ($sql, $limit=0, $offset=0) {
   $this-num_rows = false;

   // open a result set for this query...
   $result = $this-query($sql);
   if (! $result) return (false);

   // save the number of rows we are working with
   $this-num_rows = @pg_num_rows($result);

   // moves the internal row pointer of the result to point to our
   // desired offset. The next call to pg_fetch_assoc() would return
   // that row.
   if (! empty($offset)) {
   if (! @pg_result_seek($result, $offset)) {
   return (array());
   }
   }

   // gather the results together in an array of arrays...
   $data = array();
   while (($row = pg_fetch_assoc($result)) !== false) {
   $data[] = $row;

   // After reading N rows from this result set, free our memory

   // and return the rows we fetched...
   if (! empty($limit)  count($data) = $limit) {
   pg_free_result($result);
   return ($data);
   }
   }

   pg_free_result($result);
   return($data);
}

//--

?

The next problem I have is that in the migration to PDO, there is no 
'pg_result_seek' function equivalent.  So, I guess that means that in 
the PDO model, there is no option #2.  Does that mean my only 
alternative is to run option #1 in PostgreSQL?


I hate having to write 2 queries to get one set of data ... especially 
when those queries start getting complex.


Dante

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



Re: [PHP] paging results in large resultsets: mysql vs postgresql?

2006-06-15 Thread D. Dante Lorenso

Richard Lynch wrote:

3. use the built-in cursor of PostgreSQL which pre-dates MySQL
LIMIT and OFFSET clauses, which are non-standard hacks Rasmus
introduced back in the day.


Care to elaborate?  Cast into context of PDO if you can...?

Dante

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



Re: [PHP] Calculating difference between two days

2006-06-14 Thread D. Dante Lorenso

[EMAIL PROTECTED] wrote:

I need to calculate no. of days between two dates, actually between date
stored in DB and today's date.
Does anybody has an example I can use?
  


Your database will have this function.  In PostgreSQL:

   SELECT data_column - NOW() AS date_diff;

There are similar functions for MySQL.  Otherwise, consider
converting your dates to unix time and subtracting the two
numbers to find the date difference in seconds.  These maay also be
your friends:

   http://us3.php.net/manual/en/ref.datetime.php
   http://us3.php.net/manual/en/function.mktime.php
   http://us3.php.net/manual/en/function.date.php

Dante

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



Re: [PHP] Checking for empty()

2006-06-14 Thread D. Dante Lorenso

Ashley M. Kirchner wrote:
I have a form with various fields on it that I want to make sure 
aren't empty or the user didn't just hit the space bar or return (in a 
text field).  What's the best way to do this?  Seems empty() will fail 
on a textarea if the user simply hits a space or return and submits 
the form.


You can always 'trim' before you do the empty check.  Just assign to a 
variable first since empty doesn't do non-var expressions


$value = trim($value);
if (empty($value)) {
   // error not filled in
}

Of course, you'll also want to validate the data type is a string or 
number also, etc...and not an array.  This is the goal of the up and 
coming input filtering features.


Dante

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



Re: [PHP] declaring a class as stdClass?

2006-06-14 Thread D. Dante Lorenso

Mariano Guadagnini wrote:

Hi list,
I hace an existencial doubt: i've seem many scripts declaring classes 
as stdClass. In the documentation (for PHP5 and also for 4), it says 
that this class is internal of php, and should't be used. By the 
manner I saw it's being used, i guess that it can be handy to create a 
'generic' or so class, and append members when needed on the fly, 
without the need for a formal class declaration, but i could't find 
any good source explaining that. Has somebody some info about?


Also, along the lines of this same question, I can do this in PHP very 
easily:


   ?php
   $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 
'purple');

   $data = (object) $data;
   print_r($data);
   ?

And my object is magically created for me as an instance of stdClass.  
Is there a way to cast as some other type of class?


   ?php
   $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 
'purple');

   $data = (MyCustomClass) $data;
   print_r($data);
   ?

I ask this because the cast in my first example, the (object) cast is 
WAY faster than using the manual approach of:


   ?php
   $data = array('apple' = 'red', 'banana' = 'yellow', 'plum' = 
'purple');

   $MYCLASS = new MyCustomClass();
   foreach ($data as $key = $value)
  $MYCLASS-$key = $value;
   }
   ?

Dante

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



Re: [PHP] binary zero evaluates as true!?

2006-06-08 Thread D. Dante Lorenso

Jon wrote:
Seriously guys... am I completely missing something important here?  
An empty array evaluates as false.  The null character evaluates as 
false.  The STRING 0 even evaluates as false yet a binary zero does 
not?


Even better yet bindec() doesn't appear to be binary safe so it will 
work for a string representation of binary data where the 0's and 1's 
are ascii characters but pass it an actual binary string and it always 
returns 0.


(sigh)

Someone help me understand this.  Isn't this a bug or oversight?


The character '0' (zero) is not the same as a byte with all bits turned off.

   (char) '0' = (binary) '0011' = ord('0') = (int) 48

'bindec' returns the decimal equivalent of the binary number represented 
by the binary_string argument.  Note the BINARY STRING key word.  I'm 
guessing a Binary String is a string consisting of the characters '0' or 
'1' not bits.  Each character is 8 bits, so a binary string is a 
sequence of the characters #48 and #49 from the ASCII table.


The 'character' ZERO is written with bits 0011 in binary.  This 
binary could be interpreted as either a character or an integer.  If the 
binary is read as an integer, you'll get INT 48.  INT 48 is NOT FALSE.  
Casting from string to int to 'binary string' is done even when you 
might not want it.  Are you sure you are evaluating your binary 
'' properly as you claim?  Send a sample code, otherwise, see 
the following example:


--
pre
?php

$zero = (string)'0';
$one = (string)'1';
var_dump($zero);
var_dump($one);
printf(char: %s, ord: %d, byte: %08b\n, $zero, ord($zero), $zero);
printf(char: %s, ord: %d, byte: %08b\n, $one, ord($one), $one);

// string(1) 0
// string(1) 1
// char: 0, ord: 48, byte: 
// char: 1, ord: 49, byte: 0001

$zero = (int)'0';
$one = (int)'1';
var_dump($zero);
var_dump($one);
printf(char: %s, ord: %d, byte: %08b\n, $zero, ord($zero), $zero);
printf(char: %s, ord: %d, byte: %08b\n, $one, ord($one), $one);

// int(0)
// int(1)
// char: 0, ord: 48, byte: 
// char: 1, ord: 49, byte: 0001

$zero = unpack('C', (string)'0');
$zero = array_pop($zero);
$one = unpack('C', (string)'1');
$one = array_pop($one);
var_dump($zero);
var_dump($one);
printf(char: %s, ord: %d, byte: %08b\n, $zero, ord($zero), $zero);
printf(char: %s, ord: %d, byte: %08b\n, $one, ord($one), $one);

// int(48)
// int(49)
// char: 48, ord: 52, byte: 0011
// char: 49, ord: 52, byte: 00110001

?
/pre
--

Dante

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



Re: [PHP] remove last comma in string

2006-06-08 Thread D. Dante Lorenso

weetat wrote:

Hi all,

 I am using php 4.3.2 and mysql , linux.

 I have a sql statement below :

UPDATE tbl_chassis_temp SET  country = 'Singapore',  city 
'SINGAPORE',  building = 'Tampines Central 6',  other = 'Level 03-40',


I need to remove the last comma from sql text above.
I have tried using substr and rtrim , without any success ?
Anyone have any suggestion ?


http://us2.php.net/manual/en/function.trim.php
trim: 4.1.0 The optional charlist parameter was added.

$str = UPDATE tbl_chassis_temp SET  country = 'Singapore',  city 
'SINGAPORE',  building = 'Tampines Central 6',  other = 'Level 03-40', ;

$str = trim($str, ', ');
print $str;

Dante

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



Re: [PHP] binary zero evaluates as true!?

2006-06-08 Thread D. Dante Lorenso

Jon wrote:
The second thing that needs to be said here is simply a re-statement 
of the original, this time more verbosely.  The list of things in php 
that evaluate as false is as follows:


* the boolean FALSE itself
* the integer 0 (zero)
* the float 0.0 (zero)
* the empty string, and the string 0
* an array with zero elements
* an object with zero member variables (PHP 4 only)
* the special type NULL (including unset variables)
* SimpleXML objects created from empty tags

now, all i'm saying is that if, of all ungodly things, the literal 
string 0 and empty arrays evaluate to false, isn't it appropriate to 
expect a binary zero to evaluate to false as well?  Maybe i still 
don't get it.   :(


Jon,

You are correct about the behavior you are observing, sorry I doubted 
your ability/methods.  Here is a much shorter example of what you are 
trying to do:


?php
// start with int '0'
$as_int = (int) 0x0;
var_dump($as_int);

// convert into to binary string
$as_binstr = (string) pack('C', $as_int);
var_dump($as_binstr);

// cast binary string as boolean
$as_bool = (boolean) $as_binstr;
var_dump($as_bool);
?

// int(0)
// string(1) !~unprintable~!
// bool(true)

You want to know WHY a single byte of all 8 bits set to '0' does not 
evaluate as FALSE.  I don't know the answer, but my theory is as follows:


Perhaps binary strings are not a normal everyday kind of string.  If you 
have a binary string, you probably got it from a binary place like a 
file or stream.  If you read a file and that file contains one byte and 
that byte is all , then how is that FALSE when you got 1 byte 
not 0 bytes.  I might believe that a binary string should always be TRUE 
if the length is greater than ZERO bytes in length.  Since binary files 
are not meant to be looked at, perhaps length is all that determines 
their truth?


Oddly, if you start with this in the example above:

   $as_int = (int) 48;

Then, the is_bool will be false!  Ok, now I'm with you about odd 
behavior and wanting a better answer ;-)  You can't really use the 
bitwise operators on your binary string either.  From the manual:


   Bitwise operators allow you to turn specific bits within an integer 
on or
   off. If both the left- and right-hand parameters are strings, the 
bitwise

   operator will operate on the characters' ASCII values.

I think the best bet would be to unpack the binary string into a format 
that PHP will play nicely with.  Most likely if you are looking at a 
single byte, unpacking as an int is the way to go.


Dante

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



[PHP] Try XMLWriter ... was Re: [PHP] OO purism sucks - sell me on PHP5?

2006-06-02 Thread D. Dante Lorenso

[EMAIL PROTECTED] wrote:

What are some of the other killer features of PHP5 that I may be sleeping on 
here.
  


You have got to get your hands on XMLWriter.  I don't write any XHTML 
inside php any more.  I've wrapped the XMLWriter object inside my own 
object and now I can create 100% properly escaped XHTML without ever 
using a '' or '' symbol:


?php
$XML = new XTag('a', 'href', $href, 'title', 'This is a test  such.');
$XML-push('img', 'src', $img_src, 'width', 100, 'height', 50, 'border', 0);
$XML-pop(2); // img, a
print $XML-toXML();
// outputs: a href=[$href value here] title=This is a test amp; 
such.img src=[$img_src value here] width=100 height=50 
border=0//a

?

XMLWriter handles:

   * the escaping of characters to ensure I'm writing XHTML compliant code,
   * tags are guaranteed to open and close in the proper nested order,
   * content is encoded with UTF-8 encoding,
   * indentation of XHTML is optional
   * php code is legible without needing to backslash double and single
 quotes
   * PECL version of XMLWriter (gonna be in 5.2) contains ability to
 write raw (unescaped content) into your xml so you can merge
 already-created snippets of XHTML into your XHTML.
   * good for creating syntax valid XHTML 1.0+ strict output
   * good for creating syntax valid XML documents

There are a couple other 'gotta have' features of 5.1+ that are cool ... 
like PDO etc.  Sadly, all that is cool appears to be cutting edge and so 
documentation and examples are seriously lacking.  I find myself reading 
the source of many extensions just to try to figure out how to use 
them.  Maybe that's a sign I'm upgrading too often?  Of course, everyone 
is using 5.1.4 with XMLWriter from PECL, right?


Dante

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



[PHP] Am I supposed to be using SPL?

2006-05-31 Thread D. Dante Lorenso
I was about to write code to recursively list the contents of a 
directory when I remembered seeing an object in SPL that would do it for me:


   
http://us3.php.net/manual/en/function.recursivedirectoryiterator-next.php


But there is no documentation on this object, and although I have it in 
PHP 5.1.4, docs say it's might be only in CVS.  So, I try using it and 
get this:


?php
$dir = new RecursiveDirectoryIterator(/some/dir/path);
while($dir-valid()) {
   print $dir-current().\n;
  $dir-next();
}
?

But it doesn't seem to recurse through the directories.  In fact, this 
acts just like DirectoryIterator.  So, there must be a flag to make it 
recurse, but documentation is not there.  I see this documentation here:


   http://www.php.net/~helly/php/ext/spl/

But that just looks like the source code was parsed to generate it, 
nothing much help in seeing an example of the usage.


Is SPL meant to be used?  If so, is it experimental?  Is it documented?  
Should I stay away from SPL for production code?  What's the official word?


Dante

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



[PHP] get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?

2006-05-31 Thread D. Dante Lorenso

Jochem Maas wrote:

also take a look here:
http://www.wiki.cc/php/RecursiveDirectoryIterator

yes it's meant to be used, yes you can use it in production BUT your
a little on the bleeding edge (not very many people using it full on) AND
the whole of SPL is still a little in flex (as is php5-php6 in 
general) so

that you may be forced, occasionally, to adapt your code to changes (e.g.
constants that were formally used in SPL are now class constants.)


Wow, this is some magical stuff.  Here is my function in case it's of use:

   //--
   /**
* Magical SPL code to recursively list files in a directory
*/
   public static function get_paths_recursive($start_path) {
   $paths = array();
   $rdi = new RecursiveDirectoryIterator($start_path);
   foreach (new RecursiveIteratorIterator($rdi) as $path) {
   array_push($paths, (string) $path);
   }
   return $paths;
   }

   //--

This iterates over objects like arrays, casts objects as strings, and 
iterates
iterators.  All sorts of fun and joy enough to make your head spin.  
Seems to

work, though ;-)

Thanks for the wiki doc link, Jochem.

Dante

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



Re: [PHP] Code check

2006-05-29 Thread D. Dante Lorenso

Paul Goepfert wrote:

... What this script does is selects tomorrows date...


Here is a one-line way to find the month and day of tomorrow:

?php
list($tomorrow_month, $tomorrow_day) = split(':', date('m:d', 
time()+86400));

?

Test that ... I just wrote it off the top of my head.  Maybe that will 
simplify your code.


Dante

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



[PHP] streamlining php.ini; php.ini is not parsable with parse_ini_file

2006-05-25 Thread D. Dante Lorenso

All,

I want to clean up my PHP.ini file on production to be as streamlined as 
possible so that it's easier to work with and maintain.  It is easier to 
do a diff of my INI and the recommended INI if both files are very 
similar with whitespace removed, comments cleaned out, and keys sorted, 
etc.  I've tried to use parse_ini_file() function to parse the INI file, 
but that won't work because the 'extension = *' key is used multiple 
times in the php.ini.  parse_ini_file assumes unique assoc array is 
returned.


I'm guessing PHP doesn't actually use the parse_ini_file to read its own 
ini.


So, I then started parsing the ini myself with my own custom code and 
soon realized that PHP might not be using the [section] tags either as 
it uses the INI key=values.  Seems like the [section] tags are used more 
like suggestions for key grouping than for anything functional.  Is this 
a correct assumption?  If so, I've got the following INI reading code 
which will munch the php.ini-recommended and output just the strings 
which are not commented out.


See here and let me know if this looks like robust code:

//--
#!/usr/bin/php
?php
// we pass the name of an INI file on the command line
$script = array_shift($argv);
$ini_file_name = array_shift($argv);
if (!$ini_file_name || !file_exists($ini_file_name)) {
   die(usage: $script php.ini file\n);
}

// slurp in the whole ini file and init
$lines = file($ini_file_name);
$data = array();

foreach ($lines as $line) {
   // remove trailing comments, newlines, and start/end whitespace
   $line = trim(preg_replace(/;[^\\']*$/, , trim($line)));

   // skip blank lines, commented lines, ini sections, or anything 
without an '=' in the line
   if (!$line || $line{0} === ';' || $line{0} === '[' || strpos($line, 
'=')  1) {

   continue;
   }

   // fix spacing between equal sign
   list ($key, $value) = preg_split(/\s*=\s*/, $line, 2);
   $line = $key = $value;

   // save this key=value pair
   array_push($data, $line);
}

// sort and print all keys
sort($data);
print join(\n, $data);
?
//--

Dante

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



[PHP] Embedding PHP 5 in a C application

2006-05-24 Thread D. Dante Lorenso

All,

Can anybody give me a pointer on where I might start to learn how to 
embed Zend2/PHP 5 inside a stand-alone C application?


I realize that by asking a question like this it might imply I am not 
prepared enough to do handle the answer, but ignoring that, is there a 
document out there?


I guess I could start hacking Apache or something, but I was hoping for 
more of a tutorial/hand-holding article on the basics.


Dante

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



Re: [PHP] getting subdirectory

2006-05-23 Thread D. Dante Lorenso

Dallas Cahker wrote:

how do I get the subdirectory that a page is being pulled from.
say I have three sites running the same script and I need to determine 
which

site is which.

http://www.domain.com/subdir1
http://www.domain.com/subdir2
http://www.domain.com/subdir3

and subdir1, subdir2 and subdir3 all need different header and 
different db

and so on.
how would i get that I am in site subdir3 and not in subdir1?


$subdir = array_shift(preg_split('|/|', $_SERVER['PHP_SELF'], 0, 
PREG_SPLIT_NO_EMPTY));


Dante

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



Re: [PHP] Extensions Directory (PEAR/PECL)

2006-05-19 Thread D. Dante Lorenso

Robert Samuel White wrote:

When I ran the command:
pecl install zip-1.3.1
It intalled the zip.so file to:
/usr/local/lib/php/extensions/no-debug-non-zts-20050922/zip.so
  


Extensions are compiled with a given Zend/PHP API.  The zip extension 
you installed was compiled against the API dated 2005-09-22.  I 
complained/questioned this default behavior of 'pecl install' myself and 
asked why pecl didn't use the 'extension dir' value I already had set in 
the PHP.ini file.  The response was that the php.ini file is not the 
authoritative definition for the extension directory because there could 
in theory be many php.ini files all over the system not to mention the 
defaults which might be used if no php.ini file exists at all.



The only way I could get zip support working was to put it here: 
/usr/local/php/ext
Which is where my extensions directory is located. I've checked, and the
extensions directory is set correctly in the php.ini file. Does anyone know
where/how it would come up with this other path?
  


I've seen several people complain about this problem, but it doesn't 
seem anyone wants to change it.  If you want your life to continue 
without tons of stress, just go with the flow, don't try to customize 
your installation, and just accept the defaults.  Yeah, I didn't like 
that answer either.


In summary:  Change your php.ini file to match the 
'no-debug-non-zts-20050922' default directory and your problems will go 
away.


Dante

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



[PHP] Bug in XMLWriter?

2006-05-19 Thread D. Dante Lorenso
I am using XMLWriter with PHP 5.1.4 and find that it doesn't behave as I 
expect.  I am under the impressing that until I call 'endElement', I 
should be free to continue adding attributes to an opened element 
regardless of whether I have already added elements or text below it. 
Look at this sample code:


?php
//--
// create an object to write to an in-memory buffer
$XML = new XMLWriter();
$XML-openMemory();

// start new element and add 1 attribute
$XML-startElement(a);
$XML-writeAttribute(href, http://www.google.com;);

// add a text node
$XML-text(Google);

// add another attribute (DOES NOT WORK)
$XML-writeAttribute(target, _blank);

// add more text
$XML-text( Go There);

// end the element and output so we can see what we have
$XML-endElement();
print htmlspecialchars($XML-outputMemory());
//--
?

output: a href=http://www.google.com;Google Go There/a

If you notice, the 'target=_blank' attribute was silently ignored.  
However, if I move that statement above the -text() method call, it 
will work as expected.  Is this a bug or a feature I don't know about?


Dante

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



Re: [PHP] Re: Bug in XMLWriter?

2006-05-19 Thread D. Dante Lorenso

Rob Richards wrote:

Expected behavior. See comments within code snippet.

D. Dante Lorenso wrote:
I am using XMLWriter with PHP 5.1.4 and find that it doesn't behave 
as I expect.  I am under the impressing that until I call 
'endElement', I should be free to continue adding attributes to an 
opened element regardless of whether I have already added elements or 
text below it. Look at this sample code:


?php
//--
// create an object to write to an in-memory buffer
$XML = new XMLWriter();
$XML-openMemory();

// start new element and add 1 attribute
$XML-startElement(a);
$XML-writeAttribute(href, http://www.google.com;);

// add a text node
$XML-text(Google);

Here you just closed the starting element tag and moved into content.


So adding a text node closes the starting tag?  That shouldn't happen.

Seems to me that this is non-intuitive.  I would expect that until I 
call 'endElement' that the node is still constructible.  Internally it 
should work something like DOM where the node is not 'serialized' to xml 
tag form until the endElement is called.  That way, attributes could 
still be defined even after 'text' nodes were appended.

// add another attribute (DOES NOT WORK)
$XML-writeAttribute(target, _blank);

If you check the return value (FALSE), you will see it failed.
The writer is positioned within element content so cannot write an 
attribute. Attributes must be written while still positioned within 
the element's start tag.


If you look at XML as a tree, despite delving deeper into the tree 
(adding text node), as I walk back up, I should be positioned back on 
the element I opened with 'startElement'.  Turning the node into a 
string should not occur until the leaf nodes are closed.


I understand slightly more memory will be consumed the way I define it, 
but the object would certainly be more useful.  In the way I extend 
XMLWriter, I have a method like this:


?php
class A extends XMLWriter {
...
//
public function push() {
   $args = func_get_args();

   // create new node
   $this-startElement(array_shift($args));
  
   // we have a text node

   if (count($args) % 2) {
   $this-text(array_pop($args));
   }

   // add attributes
   for ($i = 0; $i  count($args); $i += 2) {
   $this-attr($args[$i], $args[$i +1]);
   }
}

//
...
}
?

The way this works is as follows:

   * first argument is the tag name
   * last argument (if present and even number of arguments) is the
 text value inside the node
   * middle arguments are attribute = attribute_value pairs of 2

After this node is created, I still want to use $X-attr() to set more 
attributes.


?php
$X = new A();
$X-push(a, href, http://www.php.net;, Click Here);
if ($want_new_window) {
   $X-attr(target, _blank);
}
print $X-to_string();
?

I have an object like this already written on top of DOM, but found 
XMLWriter to be more attractive because of better memory utilization.  
But still, 'endElement' doesn't do what it sounds like it does if the 
element is closed long before it gets called.


Is it possible to change this behavior?

Dante


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



Re: [PHP] Does PECL install modify my php.ini? or even look at it?

2006-05-16 Thread D. Dante Lorenso

Richard Lynch wrote:

On Thu, May 11, 2006 6:02 pm, D. Dante Lorenso wrote:
  

 pecl install memcache


Is it possible that pecl has an --extension-dir flag to tell it WHERE
to install stuff, or perhaps an optional command line arg or ...
Cuz, really, the odds on it being where you want it to be are pretty
slim.
  


Odds would be increased if 'pecl' would look at what I've already 
declared in the PHP.ini file ;-)


Dante

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



Re: [PHP] Does PECL install modify my php.ini? or even look at it?

2006-05-16 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, May 16, 2006 10:34 am, D. Dante Lorenso wrote:
  

Richard Lynch wrote:


On Thu, May 11, 2006 6:02 pm, D. Dante Lorenso wrote:

pecl install memcache

s it possible that pecl has an --extension-dir flag to tell it
WHERE
to install stuff, or perhaps an optional command line arg or ...
Cuz, really, the odds on it being where you want it to be are pretty
slim.

Odds would be increased if 'pecl' would look at what I've already
declared in the PHP.ini file ;-)


Okay, then you need to add a parameter to the command line to tell
pecl where your php.ini file is, because it is *NOT* going to be in
the place pecl thinks it will be on many many many machines.
  

/usr/bin/php knows where the php.ini file is and /usr/bin/pecl is written
in PHP.  It boils down to an ini_get() call.  Sounds like your fear of
not knowing where the php.ini file is located is already alleviated.


You haven't done anything but change the keywords and force pecl to
dig through a php.ini file instead of just providing the info in the
first place.
  


Digging through an ini file?  I know you aren't trying to tell me that 
this is difficult drudgery.  php already digs/dug through the php.ini 
file and yes, if I have to provide another command-line argument for 
something that is already known THAT is drudgery.


But let's not argue this.  I've just adopted the default pecl extension 
dir as my php.ini value so MY problem is solved, but for simple academic 
debate, I think pecl could/should be smarter (especially if you actually 
WANT developers to use it).


Dante

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



[PHP] xmlwriter_write_raw() not in 5.1.4 yet?

2006-05-14 Thread D. Dante Lorenso
I'm on the latest and greatest PHP 5.1.4.  I can see the function I 
think I want in the manual:


   http://us3.php.net/manual/en/function.xmlwriter-write-raw.php

But the manual says it's only in CVS.  I confirmed that I don't have it:

*Fatal error*: Call to undefined function xmlwriter_write_raw() in 
*.php* on line ***


*I am hoping that this function would let me write already-created XML 
into the XML I am writing and avoid the , , and  escaping of content 
which is normally done.


Zend summary was talking about it back in December.  We've had a couple 
version updates since then.  Still not in the source?


   http://www.zend.com/zend/week/week268.php#Heading8

Anyone know the status of this function, if it does what I wany, and 
when I can start using it?


Dante

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



Re: [PHP] Re: SimpleXML is creating nodes when it shouldn't...

2006-05-12 Thread D. Dante Lorenso

Marcus Boerger wrote:

I think that's a bug and not a feature.  Why was this changed?


It is called write support. I think we are going to add a flag
so that one can specify whether write support is enabled or not.
  


Creating data without using '=' assignment or calling a function is 
scary and somewhat 'magical' behavior.  When I 'read' from a SimpleXML 
node and cast that read into an array context, I NEVER expect to 
actually create an array on the object I am reading from.  If I do a SET 
(__set), I'd be ok with the magical behavior:


   $xmlstr = testitem1/item/test;
   $xml = simplexml_load_string($xmlstr);
   $xml-nonexist = array();

But if I'm doing a GET, changing the structure of the object is very bad:

   foreach ($xml-nonexist2 as $nonexist2) {
   }

Adding a flag is fine and all, but I definitely don't want that flag to be 
inside an INI file.  We don't need yet another flag which causes the language 
to behave differently under different circumstances.  Can't you distinguish 
between __get and __set on the object and handle it differently that way?  If 
not, the flag needs to somehow be set in code and not in an INI file with the 
default behavior to be NO, do not enable write support.  This is a bad break in 
BC from such a minor version upgrade of 5.1.2 to 5.1.4.

Dante

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



[PHP] PHP SRM, a dead project?

2006-05-12 Thread D. Dante Lorenso

All,

I'm interested in a PHP application server that is non-webserver based 
which I can run on Linux.  I was hoping for something like:


   * http://www.vl-srm.net/index.php

Does anyone know about this project?  It appears to be dead.  Hasn't 
been updated in a couple years.  Is there a better project that has 
evolved to take it's place?


Dante

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



[PHP] PECL / PEAR confusion (with memcache)

2006-05-11 Thread D. Dante Lorenso

All,

I'm really having a hard time making sense of PECL and PEAR.  My 
understanding is that PECL is for PHP extensions (written in C using the 
extension API) and that PEAR is a repository of PHP modules (classes 
written in PHP using the PEAR-approved framework).


PEAR VS PECL COMMANDS

On my linux box, I find two separate commands:

   * /usr/bin/pear
   * /usr/bin/pecl

But these are actually shell scripts which just invoke PHP on the 
following files:


   * php ... /usr/lib/php/pearcmd.php
   * php ... /usr/lib/php/peclcmd.php

But, when I dig even further, it looks like 'peclcmd.php' is just a 
wrapper around 'pearcmd.php' and the only thing that is different is the 
one-line define:


   * define('PEAR_RUNTYPE', 'pecl');

So, basically at this point, everything is using the same script and a 
small flag toggles the behavior.  OK, that's fine. 


SEARCH FOR MEMCACHE

I'm looking at an extension 'memcache' that I want to install.  So I see 
if there is either a class (PEAR) or and extension (PECL), right?


   * pear search memcache
 Retrieving data...0%50%no packages found that match
 pattern memcache

   * pecl search memcache
 Retrieving data...0%50%Matched packages, channel pecl.php.net:
 ===
 Package  Stable/(Latest)  Local
 memcache 2.0.1/(2.0.1 stable)   memcached extension

So there's a PECL extension, but not a PEAR module. That's fine.

INSTALL MEMCACHE

   * pear install memcache
 No releases available for package pear.php.net/memcache -
 package pecl/memcache can be installed with pecl install memcache
 Cannot initialize 'memcache', invalid or missing package file
 Package memcache is not valid
 install failed

Right, I can't 'pear' install because this is a PECL thing, not a 'pear' 
thing.  Got it.


   * pecl install memcache
 ...
 install ok: channel://pear.php.net/memcache-2.0.1

Ok, that a little bit confusing because I did a PECL install, not a pear 
install, but maybe pear and pecl both share the same domain name.  I'll 
ignore seeing pear in that URL, moving on...


CHECKING THAT IT'S INSTALLED

   * pecl list
 (no packages installed from channel pecl.php.net)

What?  I JUST installed it, why isn't it in my list?  Hmmm... I have 
another idea:


   * pear list
 Installed packages, channel pear.php.net:
 =
 Package Version State
 Archive_Tar 1.3.1   stable
 Console_Getargs 1.3.1   stable
 Console_Getopt  1.2 stable
 PEAR1.4.6   stable
 memcache2.0.1   stable

Huh?  I see my 'memcache' thing in the 'pear' list but not in the 'pecl' 
list.  So, did I install a PEAR thing or a PECL thing before?  This is 
weird.  Let's go look at the file system:


   * find /usr/lib/php -name 'memcache*'
 /usr/lib/php/.registry/memcache.reg
 /usr/lib/php/extensions/no-debug-non-zts-20050922/memcache.so
 /usr/lib/php/doc/memcache

Well, it looks like memcache was installed successfully as a linux .so 
(shared object), so it must be a pecl extension.  No idea why it shows 
up in the PEAR list and not the PECL list.  I'm thinking it might have 
something to do with that URL.  Any insights you can provide?


Dante

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



Re: [PHP] include_path and absolute paths in include functions

2006-05-11 Thread D. Dante Lorenso


Steven Stromer wrote:
For years I was lulled into thinking I understood php include 
functions...
I have always used relative paths in my include and related functions, 
for instance:

include_once (lib/included.php);
However, I am now needing to switch to absolute paths:
include_once (/lib/included.php);
This doesn't work. Generates error:
Warning: main(/lib/included.php) [function.main.html]: failed to open 
stream: No such file or directory in /var/www/sites/sitename/index.php 
on line 8
Warning: main() [function.include.html]: Failed opening 
'/lib/included.php' for inclusion 
(include_path='.:/var/www/sites/sitename') in 
/var/www/sites/sitename/index.php on line 8


You are confusing the web server's DOCUMENT_ROOT with your server's unix 
file system root directory '/'.



I would think I need to correct the include_path in php.ini, but the 
include_path seems right. The file I want to include does exist at:

/var/www/sites/sitename/lib/included.php

I always believed that the include_path and the path in the include() 
function were simply concatenated, but I now think that I am just 
plain wrong, as the error is reproducible on OS X, Fedora and 
everywhere else I test it.


Am I not taking into account some other directive that affects 
include_path, like 'doc_root' in php.ini, or 'DocumentRoot' or 
'ServerRoot' in httpd.conf? Or is this a permissions issue of some sort?


If you want to include a file which stems from the DOCUMENT_ROOT, try 
something like this:


   * include_once($_SERVER['DOCUMENT_ROOT']./lib/included.php);

Since absolute paths are relative to the server root, this will 
correctly map the full path.  Very likely from what you stated above, 
this is true:


   * $_SERVER['DOCUMENT_ROOT'] == /var/www/sites/sitename

Dante

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



[PHP] Does PECL install modify my php.ini? or even look at it?

2006-05-11 Thread D. Dante Lorenso

All,

I installed an extension via PECL and it seems to have plopped the 
extension into it's own extension directory instead of the one in my 
PHP.ini file.


pecl install memcache
   /usr/lib/php/extensions/no-debug-non-zts-20050922/memcache.so

But my PHP.ini file says to use:

grep extension_dir php.ini
   extension_dir = /www/webaps/phpext

So, I'm guessing that pecl installs where it wants to install and just 
ignores my php.ini settings?  Well, if I install a new extension, do I 
still need to edit the php.ini by hand and tell PHP where to find it?


grep memcache php.ini
   extension=memcache.so

Since the newly installed memcache.so extension was placed into that 
other directory '/usr/lib/php/extensions/no-debug-non-zts-20050922/', 
will PHP find it automatically?  Is there an 'include and activate all 
pecl-installed extensions' directive which is being run before or after 
my INI settings?


Dante

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



Re: [PHP] Re: include_path and absolute paths in include functions

2006-05-11 Thread D. Dante Lorenso
If you are using PHP 5, you might have some fun with the __autoload() 
function.  I use something like this in production:


//--
function __autoload($class_name) {
   require_once ($class_name..php);
}

function push_libs() {
   $paths = func_get_args();
   foreach ($paths as $path) {
   $ipath = 
ini_get(include_path).:.dirname(__FILE__)./.$path;

   ini_set(include_path, $ipath);
   }
}

// where are the class files?
push_libs(lib, lib/application, lib/db, lib/ui, lib/util, 
lib/xmlrpc);


//--

This code assumes that all the included library paths are relative to 
the file which contains this code.


Dante

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



[PHP] SimpleXML is creating nodes when it shouldn't...

2006-05-11 Thread D. Dante Lorenso
I've recently upgraded to PHP 5.1.4 from 5.1.2 and noticed that in 5.1.3 
there were changes made to SimpleXML.  Now, when I touch an element 
which didn't used to exist, instead of acting like it didn't exist, it 
creates it!  That's horrible!


Well, this used to work:

?php
$xmlstr = testitem1/item/test;
$xml = simplexml_load_string($xmlstr);
print_r($xml);

foreach ($xml-nonexist as $nonexist) {
   // do nothing
}
print_r($xml);
?

But now, the output of the print_r is different when I do it the second 
time because the foreach statement created nodes:


SimpleXMLElement Object
(
   [item] = 1
)
SimpleXMLElement Object
(
   [item] = 1
   [nonexist] = SimpleXMLElement Object
   (
   )
)

I think that's a bug and not a feature.  Why was this changed?

Dante

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



[PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso
Does anyone know if it's possible to reference class constants or static 
variables without having to use 'self::' all the time?


class A {
   const MY_CONSTANT = true;

   public function test() {
  echo self :: MY_CONSTANT; // works
  echo MY_CONSTANT; // doesn't work
   }
}

I don't think it is possible, but why not?  Can zend/php make it work?  
Seems it could since this works:


define('MY_CONSTANT', true);
class A {
   public function test() {
  echo MY_CONSTANT; // works
   }
}

It's just annoying my how much boiler-plate I have to write all the time.

Dante

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



Re: [PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso

John Wells wrote:

On 5/9/06, D. Dante Lorenso [EMAIL PROTECTED] wrote:

Does anyone know if it's possible to reference class constants or static
variables without having to use 'self::' all the time?

No, ... Why?  The reason is SCOPE.
As wonderful as PHP is, it can't read your mind. So if you're looking
for a constant or variable, PHP needs to know where to look.  If you
don't specify self::', PHP will look in the global scope, as it did
in your code example.  If you want it to look within your classes, you
need to *tell* it so.


As an OOP programmer, I would expect the scope search to be as follows:

  1. LOCAL: current method
  2. THIS: current instance ($this)
  3. SELF: current class  parent classes, in order of inheritance
  4. GLOBAL: globals

I really hate globals because it defeats my style of encapsulation.  If 
the search for my constant follows the search I've listed above, self 
would never be necessary unless you wanted to pinpoint 3 directly.  
Under this same line of thinking, though, '$this-' really shouldn't be 
be necessary either unless you wanted to clarify local vs this for 
same-named variables.



And is self:: really a lot of boiler-plate?  Really??

YES.

$x = ($y == self :: MY_CONSTANT || $y == self :: MY_CONSTANT2);
vs
$x = ($y == MY_CONSTANT || $y == MY_CONSTANT2);

My philosophy is that the more code which is written, the greater the 
probability of bugs.  Writing less code means less to read and less to 
read means easier to comprehend.


From what I can tell, PHP only uses 1) LOCAL and 4) GLOBAL scope unless 
you specifically use $this or self, but I just don't think those should 
be necessary.  Other than that's just the way it is, why IS it 
necessary to use $this and self?


Dante


class A {
const MY_CONSTANT = true;

public function test() {
   echo self :: MY_CONSTANT; // works
   echo MY_CONSTANT; // doesn't work
}
}

I don't think it is possible, but why not?  Can zend/php make it work?
Seems it could since this works:

define('MY_CONSTANT', true);
class A {
public function test() {
   echo MY_CONSTANT; // works
}
}

It's just annoying my how much boiler-plate I have to write all the 
time.


Dante

--
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



Re: [PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso

D. Dante Lorenso wrote:

As an OOP programmer, I would expect the scope search to be as follows:
  1. LOCAL: current method
  2. THIS: current instance ($this)
  3. SELF: current class  parent classes, in order of inheritance
  4. GLOBAL: globals


Actually, 2 and 3 are really the same but only vary whether the class 
member was referenced via an object or statically, and this SHOULD 
already be known to PHP based on the class declaration.  So, forcing a 
programmer to constantly embed the 'this is a static reference (self::)' 
or 'this is not a static reference ($this-)' prepended to each variable 
is definitely boiler-plate, redundant, and not necessary.


Dante

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



[PHP] throttle output streamed from a file?

2006-05-09 Thread D. Dante Lorenso

All,

I have a file which I want to stream from PHP:

   readfile($file_name);

However, this function has the problem that it reads the whole file into 
memory and then tries to write it to output.  Sometimes, you can hit the 
memory limit in PHP before the file contents are completely output 
resulting in 2M or 8M truncation of output.  I have seen code posted to 
the readfile user comments which hints at trying a userspace 
'readfile_chunked' function to break the file into smaller parts, but 
this is still not entirely what I want:


   http://us2.php.net/manual/en/function.readfile.php

My specific case is this.  I have a queue of very large files that I'd 
like to output in series.  I want to do something equivalent to this:



   readfile($big_file1); // 20 MB
   readfile($big_file2); // 20 MB
   readfile($big_file3); // 20 MB
   readfile($big_file4); // 20 MB

but I really don't want to start writing $big_file2 until $big_file1 has 
been written and I don't want PHP to consume 20 MB at a time either.  
Ideally I'd like to have an output buffer size of NN bytes and only let 
PHP fill that buffer until the client has read enough of the bytes to 
warrant another refill.  That way, I might only consume about 1MB 
sliding window of output.


To do this, I would think I need a function in PHP which will output a 
buffered stream with blocking enabled.  Can anybody point me in the 
right direction?


Dante

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



Re: [PHP] throttle output streamed from a file?

2006-05-09 Thread D. Dante Lorenso

Jochem Maas wrote:

D. Dante Lorenso wrote:

All,

I have a file which I want to stream from PHP:


it's not that relevant, but, I don't thinking streaming is the correct 
term.

your merely dumping a files' content to std output.



   readfile($file_name);


the trick you need to employ involves opening the file and 
reading/dumping

it in suitably sized chunks.



However, this function has the problem that it reads the whole file 
into memory and then tries to write it to output.  Sometimes, you can 
hit the memory limit in PHP before the file contents are completely 
output resulting in 2M or 8M truncation of output.  I have seen code 
posted to the readfile user comments which hints at trying a 
userspace 'readfile_chunked' function to break the file into smaller 
parts, but this is still not entirely what I want:


   http://us2.php.net/manual/en/function.readfile.php

My specific case is this.  I have a queue of very large files that 
I'd like to output in series.  I want to do something equivalent to 
this:



   readfile($big_file1); // 20 MB
   readfile($big_file2); // 20 MB
   readfile($big_file3); // 20 MB
   readfile($big_file4); // 20 MB

doing that would mean the client ends up with garbage - I think -
because the client justs see one big stream of data with no way of
knowing that it constitutes multiple files.
No need to worry about that problem.  The data I am streaming will be 
properly consumed by the client ;-)
using something like exec() to call the systems tar  gzip commands on 
the

files in question and then dumping out the resulting 'tarball' in chunks
as described above would be a way to achieve this.


Chunking the output is not the problem either.  I know how to fread(...) 
and fseek(...).  I can 'chunk-split' the output into smaller bytes, but 
that's also not the problem. 

The problem is that if the printing of bytes does not block during 
output, then the server (Apache/PHP) will shove as much data as it can 
into the output buffer as fast as PHP will execute.  If the client is 
only downloading at a slow rate, then we'll end up with a backlog of 
bytes written by PHP but not yet consumed by the client.   Assuming we 
have a file as large as 10 Gigabytes, that can't all fit into RAM, so 
where does the data go? 



but I really don't want to start writing $big_file2 until $big_file1 
has been written and I don't want PHP to consume 20 MB at a time 
either.  Ideally I'd like to have an output buffer size of NN bytes 
and only let PHP fill that buffer until the client has read enough of 
the bytes to warrant another refill.  That way, I might only consume 
about 1MB sliding window of output.


To do this, I would think I need a function in PHP which will output 
a buffered stream with blocking enabled.  Can anybody point me in the 
right direction?


http://php.net/streams - only I doubt that this would give you what you
want given that the client is a webbrowser and the connection is not
directly under the control of php (it's the webservers responsibility).

this is conjecture - I'm still breaking my head on streams concepts on a
regular basis!


I think I understand quite a bit of the streams stuff, but I'm trying to 
figure out how to control the output buffering and how to dump a large 
number of bytes (absolutely huge!) to a client who may be very slow.


Dante

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



Re: [PHP] throttle output streamed from a file?

2006-05-09 Thread D. Dante Lorenso

Eric Butera wrote:

On 5/9/06, D. Dante Lorenso [EMAIL PROTECTED] wrote:

To do this, I would think I need a function in PHP which will output a
buffered stream with blocking enabled.  Can anybody point me in the
right direction?
I'm probably way off base on what you're trying to do, but maybe this 
will help:

http://us2.php.net/manual/en/function.fseek.php

Not exactly.  fseek() jumps into a specific point in a file.  I don't 
have that problem.  I need to control how FAST php outputs it's data.


Dante

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



Re: [PHP] throttle output streamed from a file?

2006-05-09 Thread D. Dante Lorenso

Chris wrote:
readfile works by reading in the whole file at once - if you don't 
want it to do that, you can't use readfile.
You don't need anything complicated, or am I misunderstanding the 
question which is more likely..


$size = 1048576; // 1Meg.

$fp = fopen($big_file1, 'rb');
while(!feof($fp)) {
  $data = fgets($fp, $size);
  echo $data;
}
fclose($fp);

http://www.php.net/manual/en/function.fgets.php
Will 'echo' block until the client has consumed the whole $size amount 
of data?  If not, how fast will your while loop execute?  If 
file_size($big_file1) exceeds 1 TB, does your server end up sucking up 
all available memory?  Or does PHP crash after hitting a memory limit?


Dante

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



Re: [PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso

Jochem Maas wrote:

D. Dante Lorenso wrote:

$x = ($y == self :: MY_CONSTANT || $y == self :: MY_CONSTANT2);

I hate the spaces around the '::' whynot self::MY_CONSTANT?


Stupid PHP Eclipse code beautifier ;-)  It's what I use to beautify and 
since it always does that, I've been forced to accept it as a style rule.



$x = ($y == MY_CONSTANT || $y == MY_CONSTANT2);

My philosophy is that the more code which is written, the greater the 
probability of bugs.  Writing less code means less to read and less 
to read means easier to comprehend.

vs

that is such an oversimplication is almost laughable - 
comprenhesibility is
not at all directly bound to the number of characters used to write 
something.
My ability to identify specific tokens is blurred by the introduction of 
more tokens which amount to nothing more than boiler-plate.

if you have ever read up on how reading/comprehension works
in the human brain you should know that - 'self::' is 'read' as a 
single 'token'

once the brain is acustomed to recognizing it.
Problem is that I should never have to SEE that token at all: 0 tokens  
1 token
 From what I can tell, PHP only uses 1) LOCAL and 4) GLOBAL scope 
unless you specifically use $this or self, but I just don't think 
those should be necessary.  Other than that's just the way it is, 
why IS it necessary to use $this and self?

it's a consciencious design decision - and a very good one at that.

It's not good if it's redundant.  Look:

class A {
   public static $x = dante;
   public static function y() {
   }
}

didn't I JUST say that $x and y() are static?  Why do I have to say it 
every single time I use it:


   self :: $x;
   self :: y();

I already TOLD you it was static and heaven forbid that I change my mind 
later:


class A {
   public $x = dante;
   public function y() {
   }
}

crap, now all my other code is broken and needs to be rewritten as an 
instance dereferencer:


   $this-x;
   $this-y();

Can't I just use $x and the code knows what I am talking about since 
I've already TOLD it?


'self ::' and '$this-' should only be necessary to clarify confusion, 
but should be FORCED when no confusion exists.
(as apposed to say not making 'self' bound at runtime from the very 
beginning
of php5's inception [or atleast offering a sibling token to 'self' 
that is

bound at runtime] - but don't get me started on that!)
Oh I hear you about the need for late static binding.  We can both not 
get started on that one ;-)


Dante

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



Re: [PHP] throttle output streamed from a file?

2006-05-09 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, May 9, 2006 11:11 pm, D. Dante Lorenso wrote:

will 'echo' block until the client has consumed the whole $size amount
of data?  If not, how fast will your while loop execute?  If
file_size($big_file1) exceeds 1 TB, does your server end up sucking up
all available memory?  Or does PHP crash after hitting a memory limit?


I can't be 100% certain, but I'm pretty sure the buffering from client
and Apache and PHP for a simple fopen/fead;echo loop is going to
resolve your problems, and take care of blocking.

Yes, almost-for-sure, echo will block enough that your won't run out
of RAM.
  


I have written some test code, and yes it appears that the 'print' 
statement WILL block if the output buffer is already filled.  See this 
sample code below:


?php
define('BUFFER_SIZE', 1);

//--
function client_reader() {
   // connect back to ourself
   $myurl = 
http://.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].?server=1;

   $reader = fopen($myurl, r);
  
   // read data indefinitely but at a slow speed

   $count = 0;
   while (true) {
   print #;
   error_log(read start #.$count++);
   $buffer = fread($reader, BUFFER_SIZE);
   sleep(2);
   }
  
   // all done

   fclose($reader);
}

//--
function server_writer() {
   // build a buffer to write
   $buffer = str_repeat(#, BUFFER_SIZE);

   // write our buffer over and over as fast as our client will let us
   $count = 0;
   while (true) {
   error_log(write start #.$count++);
   print $buffer;
   }
}

//--
if (isset($_GET[server])) {
   server_writer();
}
else {
   client_reader();
}
//--
?

If you load this, the client code connect back to itself and as you can 
see, the writer writes as fast as it is allowed, but the reader will 
sleep between reads to ensure that the server writer is much faster than 
the client reader.


And the following code showed up in my server logs:

-- 8  8 --
write start #0
write start #1
write start #2
write start #3
write start #4
write start #5
write start #6
read start #0
write start #7
write start #8
write start #9
write start #10
write start #11
write start #12
write start #13
write start #14
write start #15
write start #16
write start #17
write start #18
write start #19
read start #1
read start #2
read start #3
read start #4
write start #20
write start #21
write start #22
write start #23
write start #24
read start #5
read start #6
read start #7
write start #25
write start #26
write start #27
write start #28
write start #29
read start #8
read start #9
read start #10
read start #11
read start #12
read start #13
read start #14
read start #15
read start #16
write start #30
write start #31
write start #32
write start #33
write start #34
read start #17
read start #18
read start #19
read start #20
write start #35
write start #36
write start #37
write start #38
write start #39
read start #21
read start #22
read start #23
read start #24
read start #25
read start #26
read start #27
...
-- 8 --

Ok, so, from the looks of it, the server writer seems to block on print 
when 2MB have filled the output buffer.  2MB is a good number, so I 
guess I don't need to do anything and everything magically works the way 
I would expect.


But ... if I wanted to set the output buffer smaller than 2M, like say 
just 1M or 512K, how would I go about that?  Is there a runtime 
ini_set() value?


Dante

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



Re: [PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, May 9, 2006 4:48 pm, D. Dante Lorenso wrote:
  

If
the search for my constant follows the search I've listed above, self
would never be necessary unless you wanted to pinpoint 3 directly.
Under this same line of thinking, though, '$this-' really shouldn't
be
be necessary either unless you wanted to clarify local vs this for
same-named variables.



Languages that let you get away without specifying $this- and self::
do exist...

But, in my experience, after a certain level of complexity is
achieved, you end up getting very confused very fast about where $foo
is coming from...

And it turns into a real nightmare when you inherit somebody else's code:

100,000 lines of code here
  echo $foo;
100,000 lines of code here

You really have no idea where $foo came from, do you? :-)

So I personally PREFER that one has to make it clear where the
variables are coming from.
  


Yeah, I guess I kinda agree with you about that.  '$this-' and 'self 
::' are nice so that a programmer 'reader' doesn't have to trace scope, 
but it's more work on the programmer 'writer'.  In most cases, the 
programmer writer SHOULD go the extra step because the writer can write 
the code easier than the reader can read and figure out the code.  So, 
in that regard it is nice to 'require' the notation.


I never use 'define()' in my code, however, because I think it's as 
dirty as 'global' and globals are bad in my world.  So, as a style rule, 
I usually only use all uppercase variable names when defining static or 
constant properties of an object:


   public static $MY_STATIC = array();
   const MY_CONST = true;

and therefore, in my code, if you ever find an all uppercase variable, 
it's probably scoped to the class.  Hence, dropping 'self ::' as a 
requirement when I reference class-level constants is not a scary idea 
for me. 

The other argument is that by defining the language to FORCE '$this-' 
and 'self ::', we do just that, we FORCE the use.  Not everyone has a 
problem with reading code and tracing scope.  Programmers should WANT to 
write code which is clear and easy to understand, but that style 
shouldn't be forced upon them, especially when the language CAN do 
without it.


Seems this topic could become a religious debate.  But, unlike curly up 
'funcname() {' or curly down 'funcname()\n{' debates, there is not 
choice a currently.  I'm sure there are fans of it both ways, can't we 
offer it both ways?


Dante

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



Re: [PHP] tired of referencing static variables/constants with 'self ::'

2006-05-09 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, May 9, 2006 12:42 pm, D. Dante Lorenso wrote:#1.
You might do:
define('MY_CONSTANT', true);
class A {
  const MY_CONSTANT = MY_CONSTANT;
}
Then you can sort of have the best of both worlds...
Though in a hack sort of way. :-^
  

Hehe, nice.  No thanks ;-)  Keep yer stinkin' 'define()' away from me ;-)

#2.
If it's that boiler-plate, maybe your class design is flawed...
I mean, the whole point of all this OOP stuff is re-factoring out the
commonalities of code to get a high level of code re-use. If you're
writing something so boiler-plate that it drives you crazy,
maybe you need to step back and look at the whole thing sideways and
see if your obvious class hierarchy isn't really the best hierarchy
to have chosen.
  

I'm using a 'singleton' pattern and this annoys me:

class A {
   private static $MY1, $MY2, $MY3, $MY4, $MY5;

   public function __construct() {
  if (!self :: $MY1) {
 self :: $MY1 =  self :: init_thing1();
 self :: $MY2 =  self :: init_thing2();
 self :: $MY3 =  self :: init_thing3();
 self :: $MY4 =  self :: init_thing4();
 self :: $MY5 =  self :: init_thing5();
  }
   }
   ...
}


Why couldn't I have just written:

class A {
   private static $MY1, $MY2, $MY3, $MY4, $MY5;

   public function __construct() {
  if (!$MY1) {
 $MY1 = init_thing1();
 $MY2 = init_thing2();
 $MY3 = init_thing3();
 $MY4 = init_thing4();
 $MY5 = init_thing5();
  }
   }
   ...
}

I mean, I was forced to write 'self ::' like 11 times in that 
constructor.  THAT is annoying.


I realize I am probably just venting since it's unlikely I can get 
anything changed/done on this list.  I'm just hoping some internals 
developer might see my rants and think it might be something which needs 
to be addressed within the language.  I can't be alone in my dislikes, 
can I?


Dante

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



[PHP] XML-RPC set XML encoding?

2006-05-02 Thread D. Dante Lorenso

XML-RPC gurus,

Does anyhow know how to set the character encoding for XML-RPC?

I am using the PHP built-in XML-RPC server to handle XML-RPC calls. 


?php
...
// create the XML-RPC server
$this-SERVER = xmlrpc_server_create();
...
// fetch the raw input stream which contains our XML data
$request_xml = file_get_contents(php://input);
error_log(REQUEST: .$request_xml);
...
$response = xmlrpc_server_call_method($this-SERVER, $request_xml, );
// Now we print the response for the client to read.
error_log(RESPONSE: .$response);
print $response;
...
?

ERROR LOG OUTPUT:

 REQUEST: ?xml version='1.0'?methodCall...
 RESPONSE: ?xml version=1.0 encoding=iso-8859-1?methodResponse...

The $response XML contains the following first line:

   ?xml version=1.0 encoding=iso-8859-1?

However, I want to use UTF-8 always in order to support a variety of 
character sets.  I thought that maybe the response XML encoding was 
being set to the same value as the request character set, but I want to 
force UTF-8 regardless.


Does anyhow know how to set the character encoding for XML-RPC?

Dante

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



Re: [PHP] instantiate derived class objects from within base class?

2006-05-02 Thread D. Dante Lorenso

Jochem Maas wrote:

php will not have late (runtime) static binding until at least version 6.
this sucks, it has sucked since 2003, welcome to the club of people 
who think

it sucks :-)


Oh cool there's a club, lol!?  Why, thanks for having me!  I'm a 
card-carrying member.  Let me just add this to my wish list which now 
includes:


  1. Namespaces
  2. Native Unicode
  3. Late Static Binding
  4. Threads
  5. Upload Progress Callback

You've given me better vocabulary.  I didn't realize the term was 'late 
(runtime) static binding'.  That sounds so cool.  I'm gonna try to work 
that into my everyday conversations ;-).


Damnit, I need PHP 8 already, lol ;-)

Dante

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



Re: [PHP] XML-RPC set XML encoding?

2006-05-02 Thread D. Dante Lorenso

D. Dante Lorenso wrote:

Does anyhow know how to set the character encoding for XML-RPC?


Ok, after digging through the sources, I figured this one out.  There's 
a 4th parameter to the method:


   xmlrpc_server_call_method

And, the options are all explained on this page:

   http://xmlrpc-epi.sourceforge.net/main.php?t=php_api#output_options

Not only can you set the encoding to UTF-8, but you can also and and 
remove the whitespace which was also nagging me.


Dante

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



[PHP] instantiate derived class objects from within base class?

2006-05-01 Thread D. Dante Lorenso

All,

I get a fatal error when trying to create a new instance of a derived 
class from within a static member which exists in the parent base 
class.  I think the problem is related to using this call:


   new self();

Because the 'self' refers to the parent object and not the derived 
class.  See the code below and the error message which follows:


-- 8  8  8 --
?php
// defines base functions and requires derived class to replace foo()
class A {
   protected abstract function foo();
   public static function bar() {
   $x = new self();
   $x-foo();
   }
}
// defines foo() as it should, but base class doesn't know foo exists
// when it references self()
class B extends A {
   protected function foo() {
   echo hello world;
   }
}

// show how broken things are
B :: bar();
?
-- 8  8  8 --

PHP Fatal error:  Class A contains 1 abstract method and must therefore 
be declared abstract or implement the remaining methods (A::foo) in 
.../demo.php on line 9


How do I refer to the derived class from within the base class?

Dante

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



Re: [PHP] instantiate derived class objects from within base class?

2006-05-01 Thread D. Dante Lorenso

Chris wrote:

This gives the problem away..
http://www.php.net/manual/en/language.oop5.abstract.php
Any class that contains at least one abstract method must also be 
abstract.

Make 'A' abstract:
abstract class A

Sorry for the poor example.  I did catch that after submitting my post, 
but it didn't really matter.  Adding abstract to the class doesn't solve 
the problem.  Here I do as you say and still get the error:


-- 8  8  8 --
?php
// Change to E_ALL for development/debugging
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 'On');

// defines base functions and requires derived classe to replace foo()
abstract class A {
   protected abstract function foo();
   public static function bar() {
   print __CLASS__;
   $x = new self();
   $x-foo();
   }
}
// defines foo() as it should, but base class doesn't know foo exists
// when it references self()
class B extends A {
   protected function foo() {
   echo hello world;
   }
}

// show how broken things are
B :: bar();
?
-- 8  8  8 --

Output:
A
*Fatal error*: Cannot instantiate abstract class A in *.../demo.php* on 
line *11


The problem is that when method bar() is invoked on class B statically, 
class B is complete ignored.  Since bar() is only defined inside class 
A, the B :: bar() call seems to be translated into a call of A::bar() 
and class B is no longer addressable.


My expectation is that when I call an object, the search for a method or 
property should start at the bottom-most derived object and work it's 
way up the dependency tree.  This doesn't happen, though.  It appears 
that any class can only reference base class and inherited methods and 
never derived methods.  Perhaps this is only symptomatic when referenced 
statically?


Dante
*

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



Re: [PHP] Multi-threaded port listener

2006-04-29 Thread D. Dante Lorenso

René Fournier wrote:
Anyone find any good tutorials, code samples, etc. on such a thing? 
Basically, I want to write server (in PHP) that listeners on a 
particular port, and spins off a thread/process (essentially, execute 
a separate script) for each incoming connection. There won't be a lot 
of data to process, but there will be many simultaneous 
connections—upwards of 1000s of connections (each spun off as seperate 
threads).


Building it yourself can be lots of fun and I have done this using 
stream_select, fork, and other PCNTL and IPC functions. If you like 
Pear, you can check out the Net Server package there. They have models 
to do the forking for you for each client connection:


http://pear.php.net/package/Net_Server

Although I didn't use Net Server, I did review the code to get ideas on 
how I'd like to build my server. It is useful.


Dante

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



Re: [PHP] PHP Standard style of writing your code

2006-04-29 Thread D. Dante Lorenso



So no matter what was actually typed, *I* would see:

function foo ($x) {
  //body
}

but some heretic who doesn't know any better would see:
function foo($x)
{
  //body
}

Now *THAT* would be a feature worth paying for in an IDE! :-)



Without caring what style you prefer, the correct reply to this request 
is the following:


   You seek a Code Beautifier for PHP.

I have found that only some IDE/Editor software contains such a beast.  
The convention for most software code editing tools is to have Shift + 
Ctrl + F do code formatting.  I use PHP Eclipse to handle all my code 
formatting.  It will allow you to choose your preference for braces up 
or down etc.


However...you may need to make a policy in your company.  If you use 
source control for your software, it may see changes in formatting as a 
distinct major revision.  Therefore, if you save code in your style 
and another developer opens the file and resaves in his style, then 
you'll unnecessarily make version control a nightmare.  Despite personal 
preference, you MUST adhere to the style of the project.  If you are the 
sole developer, you define that style.  If you are a coding monkey, then 
you may have to suffer with the style that the architect before you 
declared.


I can't work unless the code is formatted to my liking.  I'm the OCD 
type of programmer.  Luckily I'm also in control of coding standards 
within my company, whew!  Get PHP Eclipse and do a general search for 
PHP Code Beautifier then download some you like and try them out.


Beautiful code often contains fewer bugs.

Dante


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



Re: [PHP] I want to write a Multi-threaded PHP Application

2006-04-27 Thread D. Dante Lorenso

Gonzalo Monzón wrote:

Use Python, it is the way to go if you're willing to use mt  :-)


I've already written the multi-threaded server using Java.  I want to do 
this in PHP, however, because the PHP threads can re-use PHP classes 
I've already written and hence standardize on a single codebase and 
language.  Many other languages have threads (Java, C#, Python, Ruby, 
etc) ... which is why I'm so amazed PHP does not even list Threads as a 
priority.  You simply can't be an enterprise language without these 
basic features.  Of course, don't get me started on namespaces too ;-)


No, choosing a different language has been considered and I'd rather 
continue with my hacked multi-process PHP server solution before I am 
ready to change to a different language.


Dante


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



Re: [PHP] I want to write a Multi-threaded PHP Application

2006-04-27 Thread D. Dante Lorenso

Jochem Maas wrote:
I've already written the multi-threaded server using Java.  I want to 
do this in PHP, however, because the PHP threads can re-use PHP 
classes I've already written and hence standardize on a single 
codebase and language.  Many other languages have threads (Java, C#, 
Python, Ruby, etc) ... which is why I'm so amazed PHP does not even 
list Threads as a priority.  You simply can't be an enterprise 
language without these basic features.  Of course, don't get me 
started on namespaces too ;-)

oh yeah - threads really are basic. simple and easy to use, every
VB-scripter should be using them. btw Yahoo! seems to cope quite well 
without
threads in php - fairly 'enterprise' infrastructure and load they deal 
with no?


Every time I try to use PHP in a web server to solve a problem like 
build a file upload progress meter, somebody screams that PHP is meant 
for far more than web scripting.  Yet as soon as I try to use PHP in a 
context other than a web script, someone like yourself jumps up and 
complains that PHP needs to remain in the web scripting programming 
world only.


then again if threads are so basic for you - submit a patch that 
implements
them (and obviously fix any/all thread-safety issues in all extensions 
etc),

from what I gather that's a mammoth undertaking - given the limited
core developer resources, that is one of the reasons it's low 
priority, and then

ofcourse there is the php 'philosophy' about threads in general (of which
the php-internals mailing archive should be able to shed some light)


Evolution of the language is a must.  I AM working on trying to spec out 
an extension for PHP which would implement what I want with threading 
without having to hack zend and the core.  I might think that some other 
C developers would be more suited for the job, however, considering they 
have already done the work for such a beast in just about every other 
popular language created so far.


Obviously PHP General list is probably not the place where I can sway 
any opinions with any internals members, so I'll end this message simply 
saying that I am first seeking what already exists, what might already 
be in progress, and what still needs to be created.  At the same time, I 
like to find others would may be trying to do something similar.  I can 
not be alone in wanting to use PHP beyond what it is currently capable 
of.  I trust there must be other PHP developers who wish to see the 
language take on some of the aspects we like about other languages while 
at the same time retaining all the elements we already enjoy with the 
existing feature set.


There is no better language for web development.  Once outside it's 
niche of web scripting, tho PHP lacks severely.  Seeing how developers 
have created CLI in order to compete with PERL for cron scripting and OO 
features of PHP5 to compete with other modern OO languages, I imagine 
PHP IS trying to be more.  A Framework, Unicode, Namespaces, and Threads 
are the logical next step.  Zend Framework and Unicode have made the 
todo list, Namespaces is fighting to get on, and Threads is nowhere to 
be seen.


Dante

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



Re: [PHP] I want to write a Multi-threaded PHP Application

2006-04-27 Thread D. Dante Lorenso

Stut wrote:

D. Dante Lorenso wrote:

IMHO, if your main goal is to allow your threaded app to reuse 
existing PHP classes then your best bet is to investigate embedding 
PHP into something written in C or C++.


This is a very good point.  I have also been looking into the idea 
pitched a few years ago about SRM -- Script Running Machine.  There was 
a site set up here that held some promise:


   http://www.vl-srm.net/

The last post I can see here is dated 2004 and is one of those 
statements which claim that the project is not yet dead.  Usually 
statements like that tend to forecast the eminent demise of the 
project.  Since there have been no updates to the site in 1.5 years, I 
conclude that it is in fact dead.


SRM sold promise of creating an application server for PHP.  This smells 
a little bit like Tomcat or JBoss and so was very much of interest.  The 
current beta of SRM is designed for PHP 4, though and I want to be at 
bleading edge PHP 5 with XMLWriter and PDO etc.  As I investigate my 
options, SRM is on the list as a potential area to explore further or 
somehow to revive as a project.


Dante

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



Re: [PHP] I want to write a Multi-threaded PHP Application

2006-04-27 Thread D. Dante Lorenso

Gonzalo Monzón wrote:
I've been developing desktop applications with PHP-GTK since 2002, far 
beyond the web script context, and in the more complex projects I did, 
was a must to implement multi-process and IPC communication due to the 
lack of threading in PHP, as to deal with some issues like multiple 
tcp clients, multiple tcp server with a proxy to the application data, 
webservices, handling UI, and a lot more stuff, while doing realtime 
(the more realtime I was able of) processing of all incoming and 
outgoing data, for more than 24 hours long running time. Yes, I was 
able to be successful with such a developement after a lot of pain, 
but it is not likely the most common usage for PHP.  I finally had to 
implement several parts in C, embedding PHP, and really, I was not 
happy of to cope with that, but I did not have the time to switch to 
another language as I had to re-use a lot of existing code that worked 
smooth with a multi-process approach, but without the need of so long 
running time, so many tcp clients, and so many data... I had to 
implement data containers in using C structures, as handling all that 
data from PHP taken more than 500Mb of RAM in no more than 8 hours of 
processing, interprocess syncronization mechanisms, and a lot more stuff.


Sounds to me like you are in my boat!  I have done some similar work to 
create a multi-process beast.  Here is an OO.o Presenter presentation I 
did for the Dallas PHP User's Group back in December of 2005:


   http://dantescode.com/docs/DPUG%20-%20PHP%20Server%20Applications.odp

Perhaps this will shed a little light on my very similar solution.  
Seems to me we could benefit from having some kind of threading support 
in the language to avoid all the headache of each of us building the 
same code to solve a similar problem.  I'm sure there are others like 
yourself.


Dante

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



[PHP] How does PECL and PEAR handle versioning of PHP core?

2006-04-26 Thread D. Dante Lorenso

All,

If I install PHP 5 and want to use a PECL extension, does that work the 
same as if I install PHP 4 and try to use the same extension?


One extension that I use a lot is 'memcache' from PECL:

   http://pecl.php.net/package/memcache

When I view this site, I do not see any reference to the version of PHP 
which is required.  Does it matter about PHP 5.0.5 vs PHP 5.1.2 etc?  
Can someone explain how PECL or PEAR works in order to distribute only 
compatible versions of code?


Dante

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



[PHP] I want to write a Multi-threaded PHP Application

2006-04-26 Thread D. Dante Lorenso

All,

For years I have wanted to have the ability to create a new Thread in 
PHP similar to how it is done in the Java language.  I understand the 
complexities this would involve and have mentioned the idea to the PHP 
internals list once and subsequently had the idea shot down and declared 
not likely until at least PHP 8.0.  However, my needs for a thread are 
very simple and might be able to avoid the complexities of shared memory 
and synchronization if I could somehow implement even a smaller 
extension which does what I want.  Can you entertain this concept and 
let me know if you think it is plausible?


I want to write PHP code which looks as follows:

interface Runner {
   public static function run() {}
}
class A_Runner implements Runner {
   ...
   public static function run() {
   echo (a runner\n);
   sleep(10);
   }
}
class B_Runner implements Runner {
   ...
   public static function run() {
   echo (b runner\n);
   sleep(10);
   }
}

$A = thread_create(new A_Runner());
$B = thread_create(new B_Runner());

thread_start($A);
thread_start($B);

while (true) {
   ...
   echo (main\n);
   sleep(10);
}

And the output of this process should display echo statements from all 3 
running process simultaneously.  For example:


...
a runner
main
b runner
a runner
b runner
main
...

It would be nice if the main script could invoke methods on the $A and 
$B runner objects in this format:


   $A-my_function(...);
   $B-my_function(...);

But if that wasn't possible because of shared memory issues or 
synchronization problems, maybe the thread extension could handle 
marshaling the data on the objects behalf with a function call like:


   thread_call($A,  'my_function',  [param 1, param 2, ... param N]);
   thread_call($B,  'my_function',  [param 1, param 2, ... param N]);

I would want this functionality in order to build stand-alone PHP server 
applications which continually loop in order to execute system processes 
like: email notifications, billing, data transfer, transcoding, cron 
replacements, or even game servers, etc.  I currently have a solution in 
place which does something similar, but it involves IPC and PCNTL and 
litters my server's 'ps' listing with many child processes.  Also, some 
of the PCNTL child process can become zombies and the whole 
multi-process model is not as attractive to me as a developer as the 
multi-threaded one.


Can anyone tell me whether my idea is possible, whether there exists an 
attempt at a PHP thread-like extension (failed or succeeded), and where 
I might go to pursue this idea further?


I have already seen the Net_Server PEAR package and am familiar with the 
'forking' model used in there.  It's not quite what I want.  I think 
Threads are the way to go and am exploring how I can accomplish that.


Dante

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



Re: [PHP] Filter out MS Word 'quotes' for RSS

2006-04-26 Thread D. Dante Lorenso

Richard Lynch wrote:

On Wed, April 26, 2006 4:45 am, Kevin Davies wrote:
  

Obviously I need to convert these on entry, or on output into RSS.
Does anyone know of an easy way to do this, or is it a case of identifying
each unusual character individually?



You don't necessarily need to fix your input characters as much as you 
need to fix the output characters (characters you insert into your RSS 
feed).


If you used an extension like XMLWriter or DOM to build your XML 
document, much of the character encoding is handled for you and you can 
feel reasonably confident that the XML you create is UTF-8 encoded and 
escaped properly.  With this approach, you never need to muck with entities.


Dante

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



[PHP] Upload Progress Meter - what's the latest?

2006-04-25 Thread D. Dante Lorenso

All,

I'm trying to figure out which direction the PHP community is going when 
it comes to an upload progress meter.  I've just recently discovered the 
ease of installing packages using PECL and see that this package is defined:


   http://pecl.php.net/package/postparser

Yet, there does not appear to be any code which I can install for this 
module.  Meanwhile, I find this project here:


   http://pdoru.from.ro/ (upload-progress-meter-v4.1)

I have install this patch and built an RPM to aid in mass deployment on 
our servers and it works well enough with a few minor unresolved bugs.  
I'm trying to avoid custom patches in PHP as I work on migrating toward 
clean PHP 5.1.2 and eliminate BC dependencies.  Does anyone know 
anything about the upload progress meter development and can point me in 
a better direction?


Dante

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



Re: [PHP] Upload Progress Meter - what's the latest?

2006-04-25 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, April 25, 2006 12:18 pm, D. Dante Lorenso wrote:
  

I'm trying to figure out which direction the PHP community is going


when it comes to an upload progress meter.Since that meter would necessarily be 
CLIENT side, the PHP community
is pretty much ignoring it, since PHP runs on the SERVER.
  


Everything PHP returns from a server is client side, so your argument 
seems to indicate that we need to write all of our HTML using JavaScript 
also.  No, the fact is that a client-side GUI does NOT exist, so we need 
to build it ourselves using the tools we have.  I do not have source 
control access to Mozilla, IE, Safari, and Opera, but I can control my 
own PHP source.


PHP receives uploads from clients and that client may not even be a web 
browser in all cases.  From the server side, I need to be able to monitor


   * who is currently uploading files,
   * which files are being uploaded,
   * how big are the files being uploaded,
   * how much time has passed since upload began, and
   * what percentage of those files is completed

I do not need to return this data to a client at all times.  Sometimes I 
just want to use the data system administration, analysis, and 
tracking.  The most popular need would be for returning the information 
to the client, however, as you suggest.


Right now, PHP stops executing code from the time an upload begins until 
the time it is completed.  In other languages like PERL as CGI, you can 
read STDIN directly in order to slurp in large POST data like file 
attachments.  In such a case as that, solving this problem is trivial.  
Since PHP locks a programmer out of the loop during parsing and 
importing POST and GET variables, we need PHP code to break into that 
loop and return callback functions or update internal data structures 
directly. 

Part of the problem in addition to collection of the data is being able 
to share it with other PHP instances.  Remember that PHP runs in Apache 
in most cases and does not have shared memory between PHP instances.  
Therefore, writing the upload data to an external data storage is 
necessary.  That external storage could be Sqlite, PostgreSQL, MySQL, 
files, or even Memcache.  I would love to see a memcache-like solution.  
But more importantly, I would like to see a solution which is adopted by 
the community rather than miserably hacked together then not supported 
and abandoned.



Anything you see with PHP upload progress meter together has to be
some kind of hack whose under-pinning is NOT PHP at all, but is
JavaScript or similar client-side technology.
  


Not true.  The graphical display is HTML, DHTML, JavaScript, etc...but 
the means of monitoring the progress from the server side MUST be done 
with PHP.  The code that I have seen so far requires hooks into PHP 
which execute callback functions periodically in order to update the 
progress of uploaded files as PHP processes input.

Why don't you ask the guys who write BROWSERS why *they* don't provide
a nice API/interface to display progress, or, better yet, why the
browser itself doesn't just do it once and for all for everybody?
  
That is a good idea, and I will recommend it for future solutions. For 
short term, that is not the focus of this email.


Dante

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



Re: [PHP] Upload Progress Meter - what's the latest?

2006-04-25 Thread D. Dante Lorenso

Richard Lynch wrote:

On Tue, April 25, 2006 5:28 pm, D. Dante Lorenso wrote:
  

Everything PHP returns from a server is client side, so your


Oh yeah.  I forgot to say...
The above presumption is patently false.
  


Let me clarify:  Assuming client/server architecture, if PHP is on the 
server side then something else needs to be on the client side to 
interpret the output of the PHP server.  That output is what PHP returns 
and it is interpreted and rendered on the client side by definition.


Alternatively:  If it is not meant for the client to receive, it is not 
(should not) be output by PHP.


Dante

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



Re: [PHP] Upload Progress Meter - what's the latest?

2006-04-25 Thread D. Dante Lorenso

Richard Lynch wrote:

Anything you see with PHP upload progress meter together has to
be some kind of hack whose under-pinning is NOT PHP at all, but is
JavaScript or similar client-side technology.

Not true.  The graphical display is HTML, DHTML, JavaScript, etc...but
the means of monitoring the progress from the server side MUST be done
with PHP.



I'm sorry.  Your original post sounded (to me) like you wanted a
progress meter on the browser (client-side) for the user to see their
files uploaded.
  


Yes, I want that also.  Really, I want the feature to exist in the PHP 
language regardless of how I intend to use it.  That's the beauty of a 
programming language vs a program.  I want the tools to be able to build 
what I want however I might want it at the time.



Presumably even the worst browsers have some concept of how large the
file is, and how many bytes have been sent to the server.
So you certainly DO NOT need server-side information to implement a
client-side progress meter of the progress of a file upload!
  


Agreed.  I SHOULD not NEED this feature.  Other server-side languages 
exist, so I technically don't NEED PHP either.  I don't really want to 
debate whether this feature should exist or not, but it seems to me that 
the replies I've gotten from this list so far suggest that internals of 
PHP development are seriously opposed to such a feature?  I am more 
interested in which project extensions are leading in momentum to solve 
the problem I am trying to solve and not blaming other projects 
(browsers) for not building the feature first.



 The code that I have seen so far requires hooks into PHP
which execute callback functions periodically in order to update the
progress of uploaded files as PHP processes input.



Yes, which is a silly place to try and fix this for client-side
progress meters, as you then generate traffic back-and-forth from the
client to measure the number of bytes received, instead of the browser
just measuring bytes sent.
  


The back-and-forth you refer to is termed 'polling'.  With a protocol 
like HTTP, polling is really the only option unless I implement a socket 
server which is capable of sending events.  This is something I may be 
building into the project also, but aside from HOW I move the 
server-side collect data back to a web client, that is independent of 
needing to collect the information on the server side in a format which 
can be accessed and read easily.



browser in all cases.  From the server side, I need to be able to
monitor

* who is currently uploading files,
* which files are being uploaded,
* how big are the files being uploaded,
* how much time has passed since upload began, and
* what percentage of those files is completed

I do not need to return this data to a client at all times.  Sometimes
I
just want to use the data system administration, analysis, and
tracking.  The most popular need would be for returning the
information
to the client, however, as you suggest.



You'd need a battery of meters, for all running processes, or at least
all the ones currently in file upload state.
  


I would like to have a list of all file uploads in progress, yes.  A 
semi-frequently updated snapshot of the information I defined would be 
sufficient.  If a callback function is invoked periodically it would be 
equivalent to firing an event and would allow a php program to log the 
data to a common data repository which could be ready by another process 
on the system.

You'd also need tie-ins to your login/authentication to determin who
is uploading files as the only answer inherent to PHP is the User
set in httpd.conf
  


Right.  Under the callback method example, I would have access to 
$_SESSION which would already contain enough information about the 
logged in account for my purposes.  This is trivial.

How big they are relies on the browser sending the correct
Content-length: for the upload.  I don't know how often they get it
right, but I'm betting that are some pretty common errors in this area
that PHP corrects for already.  So your meters would not be accurate
in some (hopefully few) cases.
  


The POST method sets the Content-length, right.  So, PHP must trust that 
the browsers are not lying.  For security purposes we don't need to 
worry about whether this number is wrong because it is only for 
display.  Processing uploaded files does not occur until the file 
completes uploading.



While I can see where this might be a useful tool to have server-side,
I can suggest several possible ways to implement some portions of it
without hacking PHP source.

First, ... you could write a tool to watch /tmp for
files and get a list of the /tmp names being uploaded.
  


Yes, this is simple.


Using filectime and filemtime would tell you the timing info -- Though
Windows will suck (as usual) as it only tracks to the nearest minute
or something...
  


Yes.  Using Linux.  This will work.


For tying the