RE: [PHP] Persistent PHP web application?

2005-01-08 Thread Lance Lovette
I wrote a PHP extension a while ago that implements executor persistence
for scalar variables and constants. I never looked much into persisting
objects, arrays or resources but it would be a useful addition to the
extension if someone wants to contribute. I haven't updated the Web site
with the latest version that compiles under 4.3.x, but if you're interested
I can send you the files that changed in the meantime. It has been immensely
useful for my projects.

http://pwee.sourceforge.net

Lance

-Original Message-
From: Josh Whiting [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 03, 2005 11:28 AM
To: php-general@lists.php.net
Subject: [PHP] Persistent PHP web application?

Dear list,

My web application (an online classifieds server) requires a set of
fairly large global arrays which contain vital information that most all
the page scripts rely upon for information such as the category list,
which fields belong to each category, and so on. Additionally, there are
a large number of function definitions (more than 13,000 lines of code
in all just for these global definitions).

These global arrays and functions never change between requests.
However, the PHP engine destroys and recreates them every time. After
having spent some serious time doing benchmarking (using Apache Bench),
I have found that this code takes at least 7ms to parse per request on
my dual Xeon 2.4ghz server (Zend Accelerator in use*). This seriously
cuts into my server's peak capacity, reducing it by more than half.

My question is: is there a way to define a global set of variables and
functions ONCE per Apache process, allowing each incoming hit to run a
handler function that runs within a persistent namespace? OR, is it
possible to create some form of shared variable and function namespace
that each script can tap?

AFAIK, mod_python, mod_perl, Java, etc. all allow you to create a
persistent, long-running application with hooks/handlers for individual
Apache requests. I'm surprised I haven't found a similar solution for
PHP.

In fact, according to my work in the past few days, if an application
has a large set of global functions and variable definitions, mod_python
FAR exceeds the performance of mod_php, even though Python code runs
significantly slower than PHP code (because in mod_python you can put
all these definitions in a module that is loaded only once per Apache
process).

The most promising prospect I've come across is FastCGI, which for Perl
and other languages, allows you to run a while loop that sits and
receives incoming requests (e.g. while(FCGI::accept() = 0) {..}).
However, the PHP/FastCGI modality seems to basically compare to mod_php:
every request still creates and destroys the entire application
(although the PHP interpreter itself does persist).

Essentially I want to go beyond a persistent PHP *interpreter* (mod_php,
PHP/FastCGI) and create a persistent PHP *application*... any
suggestions?

Thanks in advance for any help!
Regards,
J. Whiting

* - Please note that I am using the Zend Accelerator (on Redhat
Enterprise with Apache 1.3) to cache the intermediate compiled PHP code.
My benchmarks (7ms+) are after the dramatic speedup provided by the
accelerator. I wouldn't even bother benchmarking this without the
compiler cache, but it is clear that a compiler cache does not prevent
PHP from still having to run the (ableit precompiled) array and function
definition code itself.

-- 
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] Global persistent variables

2004-08-12 Thread Lance Lovette
If you have the ability to compile extensions into PHP and you're not
running under Windows you may find useful an extension I wrote that is one
solution to this problem (and more).

http://pwee.sourceforge.net/

Note that I haven't yet compiled it under anything later than PHP 4.2.1.

Lance 

-Original Message-
From: Jean-Yves Jourdain [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 10, 2004 11:37 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Global persistent variables

Hi,

Is there a way to have global persistent variable with PHP? I would like 
to reproduce the use of the ASP Application(name)= value 
possibility. The variable name will be available to every users...

Thank-you in advance,

Kind regards.

Jean-Yves

-- 
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] Keep PHP variable values between script calls - XML RPC

2004-05-27 Thread Lance Lovette
If you only need to persist a handful of request-agnostic variables you may
be able to make use of an extension I wrote. Note that it doesn't work under
Windows and I haven't tested it under PHP 4.3.x.

http://pwee.sourceforge.net/

Lance 

 -Original Message-
 From: Santiago Peirano [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, May 27, 2004 11:17 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Keep PHP variable values between script calls - XML RPC
 
 Ok, here we go.
 I would like to implement an XML-RPC server (a script of course) that 
 keeps the value of certain variables between the different 
 invocations 
 of the script.
 
 I think that it should be possible, but I don't know where to start 
 (none of the search in internet gave me a starting point).
 
 Thanks in advance
 
 Santiago

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



RE: [PHP] An extension to CREATE zips??

2004-03-16 Thread Lance Lovette
Did you try this class?

http://www.phpconcept.net/pclzip/index.en.php 

 Is there function library capable of creating zip files and
 adding files to a zip archive under the windows/apache
 platform? After some  extensive browsing I can only turn
 up read-only access functions.

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



RE: [PHP] caching variables and preloading functions

2003-06-02 Thread Lance Lovette
If you are not running PHP under a Windows platform and can compile
extensions into PHP the most efficient way to solve problem #2 may be with a
PHP extension I developed. It handles constants and provides a type of
persistent variable too. It has been immensely useful for my projects.

http://pwee.sourceforge.net/

Lance

 -Original Message-
 From: ssamuel [mailto:[EMAIL PROTECTED]
 Sent: Sunday, May 25, 2003 7:05 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] caching variables and preloading functions


 Hi,

 I am looking for a way to do the following with PHP on Apache.

 1) I have a list of functions that I would like loaded into memory when
 the Apache server starts so that other .PHPs can call these functions at
 any time.  Somewhat of a way to expand the API set for PHP.

 i.e., Say I have a file named init.php which has many functions
 defined.  When the Apache server loads, I want this file to be sourced
 so that these functions are visible to all other phps.

 2) I have several variables, that I want to be cached at server init
 time.  These variables are global variables and live until the server is
 restarted and can be accessed by any .phps.

 Are there any ways to do these?

 thanks,
 sunil.


 --
 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] Persistent values between executions

2003-03-15 Thread Lance Lovette
The most efficient way to solve your problem is with a PHP extension I
developed. It handles constants and provides a type of persistent variable
too. It has been immensely useful for my projects.

http://pwee.sourceforge.net/

Lance

 -Original Message-
 From: Mike Mannakee [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 10, 2003 11:30 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Persistent values between executions


 I have some sets of values that I have stored in several tables in a mySQL
 database.  These don't often change, but are referenced on every
 single page
 view.  While each call is quick, as a gross the load on the server is too
 high.  I would like to know if there is a way to have these sets of values
 remain persistent in the server's memory between calls from browsers, like
 environment variables, to reduce the back and forth calls to
 mySQL.  As the
 data from the calls are almost always the same, it would seem easier this
 way.

 Any thoughts?  Comments?  RTFM suggestions?

 Mike



 --
 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] Best way to set global params for entire site??

2002-10-26 Thread Lance Lovette
If you are not running PHP under a Windows platform the most efficient way
to solve your problem is with a PHP extension I developed. It handles
constants and provides a type of persistent variable too. It has been
immensely useful for my projects.

http://pwee.sourceforge.net/

Lance

 -Original Message-
 From: Monty [mailto:monty3;hotmail.com]
 Sent: Tuesday, October 22, 2002 3:27 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Best way to set global params for entire site??


 I'm building a site with PHP and most scripts need access to certain
 site-wide global parameters, such as paths and default settings,
 etc. What's
 the best way to load this information so that it's globally
 available to all
 scripts? I have a func.php file that is included in all scripts -
 do I just
 load them every time for each script in there? Or is there a more
 efficient
 way of doing this with environment variables or some other way?

 Thanks!!



 --
 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] Getting fully qualified host name

2002-10-07 Thread Lance Lovette

If you happen to be running *nix (which it sounds like you are) and want to
compile the Pwee extension into PHP you can have access to constants like
SERVER_HOSTNAME.

http://pwee.sourceforge.net

Lance

 -Original Message-
 From: Spongle [mailto:[EMAIL PROTECTED]]
 Sent: Monday, October 07, 2002 4:20 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Getting fully qualified host name


 I need to get the fully qualified host name of the local machine, like
 server.somewhere.com. Sounds simple, right? Seems not.

 I'm running a CLI script in PHP 4.3-cvs (on OpenBSD) so I have no HTTP
 or other global vars to look at, and it doesn't seem to be lying about
 in my environment (not that I want to rely on that anyway).

 The posix_uname command doesn't include the domain on non-GNU OSs. I
 can get the hostname, but not the domain. Can I get it through some
 other PHP command?

 I'd really prefer not to resort to platform-specifics like rummaging in
 /etc and parsing config files or doing something silly like a reverse
 DNS lookup...

 On some OS, this will give me the hostname:
 $hostname = `/bin/hostname`;

 However, it doesn't give me the domain, and it's highly platform
 specific (i.e. it won't work on Win).

 This seems like a pretty fundamental function that should be a
 built-in, but it doesn't seem to be possible to do this in a
 platform-independent way.

 Have I missed some php_fqdn() function?

 Any better ideas?

 --
 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] Static constants? Server persistent?

2002-10-05 Thread Lance Lovette

I wrote the PWEE PHP extension to solve this exact problem.

http://pwee.sourceforge.net

It's great for constants but it's true power comes from executor
persistent variables. I haven't updated the web site but it does work with
PHP 4.2.3.

Lance

 -Original Message-
 From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, September 29, 2002 6:59 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Static constants? Server persistent?


 This is a bit hard for me to explain but is there any way to have PHP
 store a persistent server-side constant. Something that will stay in RAM
 and is not dependent on client connection.

 For example I have this code in consts.inc file:

 define (HOME_PAGE, http://myip.com/index.html);

 But if I want access to the constant I need to include the file in every
 script that needs it.

 I am hoping there is some way to say to the PHP engine, this is a
 static constant that will never change, keep it RAM, and share it
 between invocations/children.

 Is this feasible? Is it is I could then cache whole blocks of static
 HTML and that would speed up my scripts quite a bit ... AND my my life
 as a programmer easier since I wouldn't have to always have an
 include(conts.inc) statement at the top of each of my scripts ...

 Jc


 --
 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] Generate every possible combination

2002-05-16 Thread Lance Lovette

Here's the function I use:

// array array_permute(array [, string])
//
// Returns an array containing the permutations of the values in an array.
//
// Example:
// $a = array(1, 2, 3);
// $p = array_permute($a)
//
// Result:
// p[0] = '1,2,3'
// p[1] = '1,3,2'
// p[2] = '2,1,3'
// p[3] = '2,3,1'
// p[4] = '3,2,1'
// p[5] = '3,1,2'
//
function array_permute($a, $glue = ',')
{
$retval = array();
array_permute_internal($a, $glue, $retval, 0, count($a));
return $retval;
}

// Private function used by array_permute.
function array_permute_internal($a, $glue, $retval, $depth, $ubound)
{
if ($ubound  0)
{
for ($i=0; $i  $ubound; $i++)
{
$c = $a[$depth+$i];
$a[$depth+$i] = $a[$depth];
$a[$depth] = $c;
array_permute_internal($a, $glue, $retval, $depth+1, 
$ubound-1);
$c = $a[$depth+$i];
$a[$depth+$i] = $a[$depth];
$a[$depth] = $c;
}
}
else
{
$retval[] = implode($glue, $a);
}
}

-Original Message-
From: Evan Nemerson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 16, 2002 12:17 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Generate every possible combination


I need to generate every possible combination of the the values in an array.
For example, if...

$array = Array(A, B, C);

I want to be able to do something like

print_r(magic_function($array));

which would output

Array
(
[0] = ABC
[1] = ACB
[2] = BAC
[3] = BCA
[4] = CAB
[5] = CBA
)

I really have no idea where to begin. The best lead I can think of is that
there are going to be n! elements in the output array, where n is the size
of
the input array.

Any help would be greatly appreciated.


Evan



--
Think not those faithful who praise all thy words and actions, but those who
kindly reprove thy faults.

Socrates


--
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] Creating a global variable for all PHP pages?

2002-03-20 Thread Lance Lovette

Take a look at this PHP extension and see if it will help solve your
problem. It doesn't work on Windows yet though...

http://pwee.sourceforge.net

Lance

-Original Message-
From: Warrick Wilson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 21, 2002 2:49 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Creating a global variable for all PHP pages?


I want to define a variable that I can reference on ALL of my PHP pages.
Ideally, I'd like to do it in php.ini or some similar place so that I can
modify it as I place code on different systems, but not need to make changes
in lots of different places.

I looked at the Configuration section of the manual, did web searches, tried
getenv() and using the OS environment (we're mixed Windows and UNIX boxes,
using Apache and mysql and PHP 4.1.1), and had zero luck. I was hoping that
getenv() or _ENV[] would have worked. I tried creating something in php.ini
by simply adding a line, with no luck.

Is there some way of doing this?

Warrick


--
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] Creating a global variable for all PHP pages?

2002-03-20 Thread Lance Lovette

The short answer - efficiency. The FAQ has a more elaborate explanation.

-Original Message-
From: Martin Towell [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 12:14 AM
To: 'Lance Lovette'; Warrick Wilson; [EMAIL PROTECTED]
Subject: RE: [PHP] Creating a global variable for all PHP pages?


what about a common include file?

-Original Message-
From: Lance Lovette [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 4:00 PM
To: Warrick Wilson; [EMAIL PROTECTED]
Subject: RE: [PHP] Creating a global variable for all PHP pages?


Take a look at this PHP extension and see if it will help solve your
problem. It doesn't work on Windows yet though...

http://pwee.sourceforge.net

Lance

-Original Message-
From: Warrick Wilson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 21, 2002 2:49 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Creating a global variable for all PHP pages?


I want to define a variable that I can reference on ALL of my PHP pages.
Ideally, I'd like to do it in php.ini or some similar place so that I can
modify it as I place code on different systems, but not need to make changes
in lots of different places.

I looked at the Configuration section of the manual, did web searches, tried
getenv() and using the OS environment (we're mixed Windows and UNIX boxes,
using Apache and mysql and PHP 4.1.1), and had zero luck. I was hoping that
getenv() or _ENV[] would have worked. I tried creating something in php.ini
by simply adding a line, with no luck.

Is there some way of doing this?

Warrick


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



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

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



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




[PHP] fsockopen doesn't time out for 10 minutes

2001-07-20 Thread Lance Lovette

I am calling fsockopen with a timeout parameter of 60 seconds. Despite the
timeout value however fsockopen on some servers doesn't return for 10 to 13
minutes. The error given is usually Connection timed out and sometimes No
route to host. Is this much of a delay to be expected? Is there any way to
have the script just give up on fsockopen after 60 seconds? The server OS is
RedHat 6.2.

Thanks!
Lance


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Cannot determine HOSTNAME in 4.0.6?

2001-06-29 Thread Lance Lovette

Something was changed between 4.0.5 and 4.0.6 and now there is no way to determine the 
host name of the local host from a PHP script when executed in Apache. The output of 
phpinfo shows that the HOSTNAME environment variable that existed in 4.0.5 is not 
available in 4.0.6. This affects the return value of getenv and the contents of 
HTTP_ENV_VARS. Is this a bug or a feature? Here are the variables listed in the 
Environment section of Additional Modules as output from phpinfo on two of my servers, 
one with 4.0.5 and one with 4.0.6.


4.0.5
-
LESSOPEN
USERNAME
ENV
HISTSIZE
HOSTNAME
LOGNAME
MAIL
TERM
HOSTTYPE
PATH
HOME
INPUTRC
SHELL
USER
LANG 
OSTYPE
SHLVL
LS_COLORS
_

4.0.6
-
INIT_VERSION
previous
TERM
HOSTTYPE
PATH
CONSOLE
HOME
PREVLEVEL
RUNLEVEL
SHELL
runlevel
AUTOBOOT
BOOT_IMAGE
OSTYPE
SHLVL
_


[PHP] IP of server?

2001-03-28 Thread Lance Lovette

I want to base the database a PHP script uses on the IP address of the
server running the script. What is the fastest way to get the IP address of
the server from a script? I could use environment variables but they are
unreliable (when run from cron for example, the environment doesn't have all
the variables you would expect). I wrote the following function based on a
Perl firewall script that uses ifconfig, but it has too much overhead to
call every time I connect to the database. All I really want to do is add a
conf variable to php.ini that gets read at startup and is cached from then
on. Any ideas?

Thanks!
Lance



// string gethostaddress([string])
//
// Returns the IP address of a network interface for the local host.
// Returns false on error or if the address cannot be determined.
//
// Note: This function shells the ifconfig command so call sparingly.
//
function gethostaddress($interface = "eth0")
{
$inetaddr = false; // assume failure

$ifconfig = `/sbin/ifconfig $interface`;
if (ereg("inet addr:([.0-9]+)", $ifconfig, $ifconfigparts))
$inetaddr = $ifconfigparts[1];

return ($inetaddr) ? $inetaddr : false;
}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] IP of server?

2001-03-28 Thread Lance Lovette

Thanks, but most variables such as SERVER_ADDR and SERVER_NAME are not set
when you run a PHP script from the command line (or from cron). Write a
script that calls phpinfo() and then use 'php -f' to run it and you'll see
how little environment information you get.

Lance

-Original Message-
From: wx [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 28, 2001 5:09 PM
To: Lance Lovette
Subject: Re: [PHP] IP of server?


Why just not use the built in variables:

$SERVER_ADDR
$SERVER_NAME

not that tough, :)

- Rob
- Original Message -
From: "Lance Lovette" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 28, 2001 11:27 AM
Subject: [PHP] IP of server?


 I want to base the database a PHP script uses on the IP address of the
 server running the script. What is the fastest way to get the IP address
of
 the server from a script? I could use environment variables but they are
 unreliable (when run from cron for example, the environment doesn't have
all
 the variables you would expect). I wrote the following function based on a
 Perl firewall script that uses ifconfig, but it has too much overhead to
 call every time I connect to the database. All I really want to do is add
a
 conf variable to php.ini that gets read at startup and is cached from then
 on. Any ideas?

 Thanks!
 Lance

 

 // string gethostaddress([string])
 //
 // Returns the IP address of a network interface for the local host.
 // Returns false on error or if the address cannot be determined.
 //
 // Note: This function shells the ifconfig command so call sparingly.
 //
 function gethostaddress($interface = "eth0")
 {
 $inetaddr = false; // assume failure

 $ifconfig = `/sbin/ifconfig $interface`;
 if (ereg("inet addr:([.0-9]+)", $ifconfig, $ifconfigparts))
 $inetaddr = $ifconfigparts[1];

 return ($inetaddr) ? $inetaddr : false;
 }


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]