php-general Digest 28 Jul 2005 08:37:38 -0000 Issue 3592
Topics (messages 219457 through 219469):
Re: snapshot
219457 by: Philip Hallstrom
Re: Multipage form redux
219458 by: Jim Moseby
define (true/false)
219459 by: Sebastian
219460 by: comex
219468 by: Jochem Maas
application-wide shared data/object
219461 by: Aiguo Fei
219462 by: Aaron Greenspan
219466 by: Joe Wollard
219467 by: Rasmus Lerdorf
Date confusion
219463 by: Linda H
219464 by: Rasmus Lerdorf
219465 by: Rob Agar
Re: Has anybody used amfphp? (open flash remoting + php)
219469 by: Mark Rees
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
We just bought ourselfs a very basic windows station so that we can test our
php and html applications on windows as well. For the html applications, a
simple screen shot of how it looks in internet explorer is sufficient.
I know how to handle http authentication, file uploads, streaming files back
to the browser and all that, but would like some advise on how I can control
internet explorer from php.
The scheme: a coworker logs on on the page, enters a local network url, the
scripts launches internetxplorer with that url, takes a screen shot picture
and streams that back to the browser.
Any ideas anyone?
never done this and have never used the following app, but it came up
somewhere else for a similar question... seems like it should do what you
want.
http://www.autoitscript.com/autoit3/
--- End Message ---
--- Begin Message ---
>
> Jim Moseby wrote:
> >>-----Original Message-----
> >>From: Jack Jackson [mailto:[EMAIL PROTECTED]
> >>Sent: Wednesday, July 27, 2005 3:47 PM
> >>To: php >> "[php] PHP General List"
> >>Subject: Re: [PHP] Multipage form redux
> >>
> >>
> >>hi, my first attempt at a sessions-based form is starting at
> >>
> >>http://pastebin.com/322696
> >>
> >>and I have a question. What I want to do is, after the user
> >>answers the
> >>questions in section one and they are error checked, I want
> >>to write the
> >>answers to $_SESSION() and then continue down the script to
> the next
> >>page of questions. I do *not* want to re-send the answers
> >>from page one
> >>as $_POST vars back to the user and have the user submit the
> >>answers to
> >>page 2 plus the $_POST answers from page 1.
> >>
> >>
> >>
> >>What I am doing now is clearly wrong, basically :
> >>
> >>if (empty($error)) {
> >> include_once($page2);
> >>}
> >>
> >>because that's keeping it all in one script. But how should I
> >>be getting
> >>to the next page, sending headers to a new script, and at the
> >>end of the
> >>chain the script which pulls it all together?
> >>
> >>Thanks in advance,
> >>
> >>JJ
> >
> >
> >
> > This seems so simple to me. As I understand it, you want
> to split a data
> > entry session into several pages. You don't want to
> collect the data and
> > submit it all at the end, but instead commit it to session
> variables along
> > the way. Am I missing something?
> >
> > Here's how I would do it in a nutshell:
> >
> > Page1 // User enters first batch of data, presses SUBMIT at
> bottom. Data is
> > POSTed to Page2
> >
> > Page2 // Commit data from page 1 to session variables, then
> displays form
> > for next batch of data. User presses SUBMIT, posts data to Page 3.
> >
> > Page3 // Commit data from page 2 to session variables, then
> displays form
> > for next batch of data. User presses SUBMIT, posts data to Page 4.
> >
> > ... etc etc etc (Each page begins by assigning data from
> the previous page
> > to session variables)
> >
> > Page515 // Displays all session variables set in previous
> pages, asks user
> > to confirm. User confirms by pressing SUBMIT, confirmation
> POSTed to page
> > 516, who writes it all to the database, and sends
> confirmation email.
> >
> > Personally, I would take the advice of a previous poster
> and start off
> > assigning a username and password to the user. Then store
> each page in the
> > database as the user progresses. That way, if he is
> interrupted in the
> > middle of the process, he won't lose all his data and have
> to start over.
> > He can just enter his username and pick up where he left
> off. You will just
> > have to write a script that purges old incomplete records.
> (A great job for
> > cron!)
> >
> > JM
> >
>
>
> Right. Except I would rather have it working in a session because I
> specifically do not want to have the form sending $_POST data
> back and
> forth to the browser six times for several reasons. SO I'd like to
>
> Page1 // User enters first batch of data, presses SUBMIT at bottom.
> Data is cleaned and written to SESSION, user passed to Page2
>
> repeat as necessary to last page. At last page, process and
> error check
> newest input, then commit it, plus all previously stored
> session info to
> db.
>
> Does this make sense?
>
> Thanks in advance
Makes sense. I do not believe you can do this without client-side scripting
(Javascript, AJAX, etc) You cannot (otherwise)process data that has not
been sent back to be processed.
JM
--- End Message ---
--- Begin Message ---
i never really used constants before so this may sound stupid..
when you define a constant using define() and want to return true/false
is this logical:
if($bars == 3)
{
define('BAR', 1);
}
then:
if(BAR)
{
// bars is true
}
or should i need to do an else statement as well:
if($bars == 3)
{
define('BAR', 1);
}
else
{
define('BAR', 0)
}
lastly is it more practical to just do:
if($bars == 3)
{
$bar = true;
}
i am curious what most people would use.
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.5/58 - Release Date: 7/25/2005
--- End Message ---
--- Begin Message ---
> i never really used constants before so this may sound stupid..
> when you define a constant using define() and want to return true/false
> is this logical:
http://us2.php.net/defined
--- End Message ---
--- Begin Message ---
Sebastian wrote:
i never really used constants before so this may sound stupid..
you could use constants and still sound stupid.
- that would be 'constantly sounding stupid' ;-)
when you define a constant using define() and want to return true/false
is this logical:
yes, if a little verbose ...
if($bars == 3)
{
define('BAR', 1);
}
then:
if(BAR)
{
// bars is true
}
or should i need to do an else statement as well:
if($bars == 3)
{
define('BAR', 1);
}
else
{
define('BAR', 0)
}
I _think_ you want to define BAR in both cases (but you may not
- bare in mind that its also valid to conditionally define a constant
and have other code act depending on whether the constant exists by way
of the defined() function.). but 8 lines of code to define a single constants
seems a little wastful (I find that the better my programming skills the
more dense my code becomes - I like to be able to fit as much code as is
possible, without making it ugly or unreadable, on screen) ....
to that end here is another way to write the example above.
// 'normal'
define('BAR', ($bars == 3));
// 'a bit anal'
define('BAR', ($bars === 3));
// OTT
define('BAR', (boolean)($bars === 3));
essentially, if you want BAR to act as a true/false flag
(e.g.: if (BAR) {/* go to the bar */} ) it does not really matter if
you use 1/0 or true/false but I would recommend using the boolean
values.
lastly is it more practical to just do:
if($bars == 3)
{
$bar = true;
$bar _could_ be changed (or unset) somewhere else in the code,
and is only available in the scope that it is defined
in (e.g. a function) where as a constant once defined
cannot change or be unset and is available everywhere. People
often use constants to give meaningful names to values which
would otherwise be hard to remember - to that end constants are
defined by php itself ... and also quite a few extensions ...
take for instance these:
IMG_GIF
IMG_JPG
IMG_JPEG (same as IMG_JPG)
IMG_PNG
which are alot easier to work with than:
1,
2,
4
try the following line:
<? var_dump( IMG_GIF, IMG_JPG, IMG_PNG ); ?>
}
i am curious what most people would use.
--- End Message ---
--- Begin Message ---
In ASP.Net there is the concept of "application" which is a virtual
directory on a Web server. An application can have application-wide
shared data/objects, which can be accessed by any script of that
application (i.e., scripts under the virtual directory). I have gone
through several PHP books, haven't seen it mentioned anywhere that PHP
has similar facility. I don't know if anyone has written an extention
to do something similar. Or any experience/suggestion on this matter.
To make it clear, consider the following example. I want to do
web-based dictionary. To achieve good performance, I want to load the
whole dictionary into memory when the "application" starts (e.g., when
the web server starts, or triggered when the first script under a
certain directory is requested), and build a lookup table; then create
a globally-accessible object, let's say, Application["my_dict"]; and
it provides a function to do the dictionary lookup. In a script, one
could do something like:
$definition=Application["my_dict"]->lookup( $word );
For a complete solution, it should support object locking/exclusive
access as well.
--- End Message ---
--- Begin Message ---
Hi,
Not sure if everyone would agree, but I think the best way to go about
doing this is just to make a table in a relational database. You can
restrict access permissions using MySQL if that's something you're
really concerned about, but there's basically no disadvantage to just
storing your data in a MyISAM table instead of a shared object. You can
index, sort, etc. very quickly that way. You can even load the result of
the query into your $_SESSION variable after the first time so that you
essentially have the result set cached. If indexing isn't a big deal,
I'd just say store the data in a flat file. You can always move it
outside of the web-accessible directory if you're worried about people
accessing it directly.
Alternately, you could just store the data in a PHP file and include it
in your scripts. Either way works, I think.
Aaron
Aaron Greenspan
President & CEO
Think Computer Corporation
http://www.thinkcomputer.com
--- End Message ---
--- Begin Message ---
Aiguo,
To achieve good performance, I want to load the
whole dictionary into memory when the "application" starts (e.g.,
when
the web server starts...
I'm not sure how ASP works, but in PHP you can't load something into
memory when the web server starts and keep it there. PHP 'compiles'
each script upon request and then frees up the memory it occupied.
I'd think that this would be counter productive if your looking to
achieve good performance because you'll be re-building the dictionary
on every page load.
It might be better to let another application load the data into
memory and hold it there instead of making PHP load the whole thing
every time a user requests the page/data. If it were me I think I'd
simply load the dictionary into a database and build a simple library
or class to perform queries and calculations against the dictionary.
Assuming your class definition takes care of connecting to the
database server you could lookup a word in almost the exact way you
demonstrated.
e.g.
$dict = new dictionary;
$definition = $dict->lookup($word);
If you'll need this object to be available on every page the user
sees you could always make a 'common.php' (or whatever) which would
create the object and then include that at the top of each page.
For a complete solution, it should support object locking/exclusive
access as well.
Maybe I've been a spoiled PHP programmer for too long. ;-) I'm not
sure what object locking/ exclusive access is but from the sounds of
it, there isn't a way to do this in PHP that I'm aware of. This is
assuming that you want to be able to basically remove the object from
the global scope. In PHP objects are globally accessible from the
moment they're created to the moment they're destroyed.
Good luck!
-Joe
On Jul 27, 2005, at 8:40 PM, Aiguo Fei wrote:
In ASP.Net there is the concept of "application" which is a virtual
directory on a Web server. An application can have application-wide
shared data/objects, which can be accessed by any script of that
application (i.e., scripts under the virtual directory). I have gone
through several PHP books, haven't seen it mentioned anywhere that PHP
has similar facility. I don't know if anyone has written an extention
to do something similar. Or any experience/suggestion on this matter.
To make it clear, consider the following example. I want to do
web-based dictionary. To achieve good performance, I want to load the
whole dictionary into memory when the "application" starts (e.g., when
the web server starts, or triggered when the first script under a
certain directory is requested), and build a lookup table; then create
a globally-accessible object, let's say, Application["my_dict"]; and
it provides a function to do the dictionary lookup. In a script, one
could do something like:
$definition=Application["my_dict"]->lookup( $word );
For a complete solution, it should support object locking/exclusive
access as well.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
This is the sort of thing we call a scalability killer. Loading
everything into memory on one machine and then adding locks presumably
for writing to this memory means you are limiting any sort of horizontal
scalability and you are slowing down the one machine you do have with
lock contention.
But yes, there are a number of ways to do this. PHP has all the
low-level functions you need to create, access and lock shared memory
segments. If you look at pecl/apc you can use the apc_store/apc_fetch
calls to shove an entire array or object into shared memory just once at
the beginning and then pull it out very quickly directly from memory on
each request.
Or you could write yourself a simple extension that creates the
appropriate structures in memory in the MINIT hook.
But, consider scalability issues. If you are at the point where you are
looking at concepts like this, you are probably also at the point where
you need to start thinking about horizontal scaling, load balancers,
failover, etc. A replicated database backend with a replicated copy of
the data on each web server gets you data distribution and robust
locking on the write to the master while all the reads from the local
clients are likely to come right out of the database's memory-based
request cache. The performance hit for this extra data replication and
scalability is probably smaller than you think and the added value is
extensive.
-Rasmus
Joe Wollard wrote:
> Aiguo,
>
>
>> To achieve good performance, I want to load the
>> whole dictionary into memory when the "application" starts (e.g., when
>> the web server starts...
>
>
> I'm not sure how ASP works, but in PHP you can't load something into
> memory when the web server starts and keep it there. PHP 'compiles'
> each script upon request and then frees up the memory it occupied. I'd
> think that this would be counter productive if your looking to achieve
> good performance because you'll be re-building the dictionary on every
> page load.
>
>
> It might be better to let another application load the data into memory
> and hold it there instead of making PHP load the whole thing every time
> a user requests the page/data. If it were me I think I'd simply load
> the dictionary into a database and build a simple library or class to
> perform queries and calculations against the dictionary.
>
> Assuming your class definition takes care of connecting to the database
> server you could lookup a word in almost the exact way you demonstrated.
> e.g.
> $dict = new dictionary;
> $definition = $dict->lookup($word);
>
>
> If you'll need this object to be available on every page the user sees
> you could always make a 'common.php' (or whatever) which would create
> the object and then include that at the top of each page.
>
>
>> For a complete solution, it should support object locking/exclusive
>> access as well.
>
>
> Maybe I've been a spoiled PHP programmer for too long. ;-) I'm not sure
> what object locking/ exclusive access is but from the sounds of it,
> there isn't a way to do this in PHP that I'm aware of. This is assuming
> that you want to be able to basically remove the object from the global
> scope. In PHP objects are globally accessible from the moment they're
> created to the moment they're destroyed.
>
> Good luck!
> -Joe
>
>
> On Jul 27, 2005, at 8:40 PM, Aiguo Fei wrote:
>
>> In ASP.Net there is the concept of "application" which is a virtual
>> directory on a Web server. An application can have application-wide
>> shared data/objects, which can be accessed by any script of that
>> application (i.e., scripts under the virtual directory). I have gone
>> through several PHP books, haven't seen it mentioned anywhere that PHP
>> has similar facility. I don't know if anyone has written an extention
>> to do something similar. Or any experience/suggestion on this matter.
>>
>> To make it clear, consider the following example. I want to do
>> web-based dictionary. To achieve good performance, I want to load the
>> whole dictionary into memory when the "application" starts (e.g., when
>> the web server starts, or triggered when the first script under a
>> certain directory is requested), and build a lookup table; then create
>> a globally-accessible object, let's say, Application["my_dict"]; and
>> it provides a function to do the dictionary lookup. In a script, one
>> could do something like:
>> $definition=Application["my_dict"]->lookup( $word );
>>
>> For a complete solution, it should support object locking/exclusive
>> access as well.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
--- End Message ---
--- Begin Message ---
Hi,
I must admit I am surprised at the paucity of date and time functions in PHP.
I have a date stored in a MySQL database in field of datatype date. PHP
doesn't seem to have a function I can use to format it for print. I tried
the following but regardless of the value in the date field, it displays as
'Wednesday December 31, 1969' (I know this is the day before the UNIX
epoch.).
echo '<p>'.date('l F j, Y',$start_date).'</p>';
I tried casting the field to datetime, but it didn't pass the parser.
Finally I did the following, which seems to work, but is awfully convoluted:
echo '<p>Date: '.date('l F j, Y',strtotime($start_date).'</p>';
The other thing I'm concerned about is that strtotime takes the locale into
consideration. I don't want it adjusting the date - I just want it printed out.
Is there a better way to do this?
--- End Message ---
--- Begin Message ---
Linda H wrote:
> Hi,
>
> I must admit I am surprised at the paucity of date and time functions in
> PHP.
>
> I have a date stored in a MySQL database in field of datatype date. PHP
> doesn't seem to have a function I can use to format it for print. I
> tried the following but regardless of the value in the date field, it
> displays as 'Wednesday December 31, 1969' (I know this is the day
> before the UNIX epoch.).
>
> echo '<p>'.date('l F j, Y',$start_date).'</p>';
>
> I tried casting the field to datetime, but it didn't pass the parser.
> Finally I did the following, which seems to work, but is awfully
> convoluted:
>
> echo '<p>Date: '.date('l F j, Y',strtotime($start_date).'</p>';
>
> The other thing I'm concerned about is that strtotime takes the locale
> into consideration. I don't want it adjusting the date - I just want it
> printed out.
>
> Is there a better way to do this?
If you have it in MySQL, there are a bunch of native MySQL functions to
format it on the select itself. See http://mysql.com/datetime
Or, if you want to manipulate it using PHP's functions, get MySQL to
return it to you as a UNIX timestamp.
-Rasmus
--- End Message ---
--- Begin Message ---
hi Linda
> I must admit I am surprised at the paucity of date and time
> functions in PHP.
You may want to check out the PEAR Date class:
http://pear.php.net/package/Date
Rob
--- End Message ---
--- Begin Message ---
"Taksam" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Anybody used OpenAMF+PHP? ( http://www.amfphp.org/ )
>
> It is an open-source Flash Remoting gateway. I already used it with Java
and works OK. Just wanted to know if somebody here used it with PHP and
would like to know if they recommend it or not.
>
Please don't cross-post on php.general and this list
>
>
> Tak
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
--- End Message ---