php-general Digest 22 Aug 2009 02:34:03 -0000 Issue 6298

Topics (messages 297054 through 297067):

Re: PHP/Ajax Framework - Call for Developers & Testers
        297054 by: Bob McConnell

about to run PHP script when POST data.
        297055 by: Jacky
        297057 by: Arno Kuhl

Re: Invoking functions stored in a separate directory?
        297056 by: Arno Kuhl

Re: Extract column names from a (my)SQL query
        297058 by: Nisse Engström
        297064 by: Daevid Vincent
        297065 by: דניאל דנון
        297066 by: דניאל דנון

PHP Shopping Cart Recommendation
        297059 by: sono-io.fannullone.us
        297060 by: Ashley Sheridan

PHP 5.x magic mathods quick question
        297061 by: Ralph Deffke
        297062 by: Martin Scotta

Re: Is there limitation for switch case: argument's value?
        297063 by: Daevid Vincent

Re: HTML text extraction
        297067 by: Manuel Lemos

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
From: Raymond Irving

> Hi Nathan,
> 
> I agree with you, and I believe that there are many persons
> who don't like the idea of hosting all their applications on
> a third party server. IMO there are some advantages and
> disadvantages to doing so but that's a discussion in itself.

Hosted servers are basically a trade off between doing it yourself and
paying someone else to do it. The initial choice is between installing
your own servers or spend the money to rent servers from someone else.
Most of the time it is actually the network bandwidth issue that decides
this. Can you afford a network connection that will handle the peak
loads but be unused most of the time?

But once you decide to pay someone else, you have another set of trade
offs to negotiate. What services do they provide? What systems do they
offer? How do they manage version control and updates? Are they PCI
compliant? There are a wide range of options available in the market.
Not all of them will fit your specific needs.

We just moved most of our servers from a physical hosting service to a
managed service. Where we used to maintain the OS and all software on
the server, the new service now handles that for us. The trade off is
that now we have to settle for the server package they offer. That means
we get the versions of Apache, PHP and PostgreSQL that were included in
the last production release of RHEL. If we want a newer version of PHP,
we have to take over maintenance of that component. It becomes our
responsibility to install the updates, patches, etc., for that
component.

Once you get beyond a private web site these types of decisions become
part of the management process, just as make or buy decisions are part
of the hardware procurement process. There are people out there making a
good living just guiding companies through this decision making process.

Bob McConnell

--- End Message ---
--- Begin Message ---
Hi guys,

As I know When we POST a big data(e.g. 500M) to a php script, the php script
only can run after the big data finished POST.

for example:
a.php

> <?php die('oooo'); ?>


and I post 500m data to a.php,  after that a.php cannot be died immediately.
only when the data finished post.

How can I make the a.php die before the 500m data finish?

Thanks in advance.

-- 
Regards,
Jacky

--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Jacky [mailto:newbde...@gmail.com] 
Sent: 21 August 2009 03:12 PM
To: php-gene...@lists.php.net
Subject: [PHP] about to run PHP script when POST data.

Hi guys,

As I know When we POST a big data(e.g. 500M) to a php script, the php script
only can run after the big data finished POST.

for example:
a.php

> <?php die('oooo'); ?>


and I post 500m data to a.php,  after that a.php cannot be died immediately.
only when the data finished post.

How can I make the a.php die before the 500m data finish?

Thanks in advance.

--
Regards,
Jacky

-------

Your script will die ungracefully when it runs out of execution time
(defined in php.ini)

Cheers
Arno


--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Clancy [mailto:clanc...@cybec.com.au] 
Sent: 21 August 2009 01:26 PM
To: php-gene...@lists.php.net
Subject: [PHP] Invoking functions stored in a separate directory?

I am developing an idea for a website engine which can be shared between
several different websites. Each website would have its own directory under
a common root directory, and the engine would be in a separate directory
Engine:

Root
Website_1.com, Website_2.com, Engine

The website directories would each contain the design data for that website,
consisting basically of a mixture of text files and images. The various
pages would be loaded by loading index.php from the website root directory,
and specifying a number of parameters e.g.

http://www.corybas.com/index.php?path=Holidays&level=0&item=0

I have the minimum amount of code in index.php -- just enough to set some
parameters to identify the website, and then include
../Engine/Main_prog.php.  This in turn can include any of a large number of
other include files to carry out particular functions. 

I have the prototype working nicely on my PC, and on a stand-alone basis on
a server, but now I am trying to upload the multi-website version to a
public host, and am encountering a number of problems, mainly because I have
never done any serious work with UNIX, and the host support staff don't
understand what I am trying to do.

The problems mainly relate to setting permissions to allow the website to
access the engine code. I only have a rough idea of how the permissions
work, but I think that to include engine code the website has to have read
and execute rights to it, and I also think that so far as the engine is
concerned the website will count as 'other'.  (I can easily arrange that all
temporary files are written in the website directory.)

I suspect that rather than including the engine code in index.php, it would
be better to call functions in it, so that the website only required
'execute' rights, but I don't know of any way to do this without having
anything running permanently on the server. Can anyone suggest how it can be
done?

---------

Using include ../Engine/Main_prog.php won't work for you in a production
environment. You need to create a path.php file that defines the absolute
path to the engine for each website, and include it at the top of your
website script. Then you can do something like:

   include ENGINEPATH."Main_prog.php";

You can have different path files, one for dev and one for live, that allows
you to use the same scripts for both environments and just use the
appropriate path definition script.

E.g. Windows path.php
define('ENGINEPATH','../Engine/');

Linux path.php
define('ENGINEPATH','/usr/home/Engine/');

You shouldn't really have permission problems as long as your website and
engine are on the same server. I do something similar where the bulk of my
code is below doc root, and I use path files to find the main system
directories. The beauty of it is you can change your mind about directory
structures, and just change the path file definitions without making any
changes in the application code (my path file defines about 20 directories).
It also lets you do dev on a Windows pc and deploy on a *nix box without any
problems - just use a different path file for each.

One other advantage it will give you for your particualr design is that you
can have multiple engines per server (e.g. Engine1, Engine2, etc) so that
you can bring one engine down for upgrade while still keeping sites running
on the other engines.

Cheers
Arno



--- End Message ---
--- Begin Message ---
On Wed, 19 Aug 2009 22:42:36 +0300, דניאל דנון wrote:

> Lets assume I have the following string:
> "SELECT field1, field2, field3 FROM tablename WHERE field1 = 'something' "
> 
> Is there any way to get "field1, field2, field3"? assuming it might also
> have join, left join - things like that.

If you're using MySQL, you can try mysql_field_name()
and see if it gets you anywhere. I don't think it works
on empty results though.


/Nisse

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se] 
>
> If you're using MySQL, you can try mysql_field_name()
> and see if it gets you anywhere. I don't think it works
> on empty results though.


FYI. It will.


--- End Message ---
--- Begin Message ---
You all misunderstood my question, please read my replies above...

I'm looking to extract it from a string - *I'm not executing the queries, I
only get them as a string*

And to the topic:

Since everything I found was very complicated to parse, I've crafted my own
preg pattern,

"/^(\*|[a-z_, \(\)0-9]+)[\s]+FROM[\s]+([a-z_\.
]+)\s+(WHERE[\s]+(.+)|)\s*(|ORDER BY ([a-z0-9,
])(|\s(DESC|ASC)))\s*(|LIMIT\s+([0-9]+)\s*,\s*([0-9]+))\s*$/Ui"

(Assuming this is a SELECT string, and the subject is something similar to:
* FROM table WHERE field2='field3' LIMIT 0,10

(Yes, no SELECT - I've got another function to determine whether its select,
insert, update, delete from - etc, and it returns to query without the name
of the command - "SELECT field FROM table" => "field FROM table")

(Without using joins or things like that)

But I don't have much experience crafting patterns like that - or working
with them so I'd be glad if  you think of a better way of doing it,

and.... problem is since I'm using sub-brackets, its hard to process it
since if there is WHERE and a LIMIT, then LIMIT (...) will be on $result[$n]
(for example),
But if there is no WHERE, then LIMIT (...) will be on $result[$n - 2];

How should I overcome this problem?


2009/8/21 Daevid Vincent <dae...@daevid.com>

> > -----Original Message-----
> > From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se]
> >
> > If you're using MySQL, you can try mysql_field_name()
> > and see if it gets you anywhere. I don't think it works
> > on empty results though.
>
>
> FYI. It will.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Use ROT26 for best security

--- End Message ---
--- Begin Message ---
Update: I've changed it into

"/^(\*|[a-z_,
\(\)0-9]+)[\s]+FROM[\s]+([a-z_\.]+)(\s+)?(WHERE[\s]+(.+))?\s*(LIMIT\s+([0-9]+)\s*,\s*([0-9]+))?\s*(ORDER
BY ([a-z0-9, ]+)?(\s*(DESC|ASC)))?$/Ui"


Only problem that on:
SELECT * FROM table WHERE field2='field3' ORDER BY id DESC LIMIT 0,10
it outputs

Array
(
    [0] => * FROM table WHERE field2='field3' ORDER BY id DESC LIMIT 0,10
    [1] => *
    [2] => table
    [3] =>
    [4] => WHERE field2='field3' ORDER BY id DESC
    [5] => field2='field3' ORDER BY id DESC
    [6] => LIMIT 0,10
    [7] => 0
    [8] => 10
)



On Fri, Aug 21, 2009 at 9:38 PM, דניאל דנון <danondan...@gmail.com> wrote:

> You all misunderstood my question, please read my replies above...
>
> I'm looking to extract it from a string - *I'm not executing the queries,
> I only get them as a string*
>
> And to the topic:
>
> Since everything I found was very complicated to parse, I've crafted my own
> preg pattern,
>
> "/^(\*|[a-z_, \(\)0-9]+)[\s]+FROM[\s]+([a-z_\.
> ]+)\s+(WHERE[\s]+(.+)|)\s*(|ORDER BY ([a-z0-9,
> ])(|\s(DESC|ASC)))\s*(|LIMIT\s+([0-9]+)\s*,\s*([0-9]+))\s*$/Ui"
>
> (Assuming this is a SELECT string, and the subject is something similar to:
> * FROM table WHERE field2='field3' LIMIT 0,10
>
> (Yes, no SELECT - I've got another function to determine whether its
> select, insert, update, delete from - etc, and it returns to query without
> the name of the command - "SELECT field FROM table" => "field FROM table")
>
> (Without using joins or things like that)
>
> But I don't have much experience crafting patterns like that - or working
> with them so I'd be glad if  you think of a better way of doing it,
>
> and.... problem is since I'm using sub-brackets, its hard to process it
> since if there is WHERE and a LIMIT, then LIMIT (...) will be on $result[$n]
> (for example),
> But if there is no WHERE, then LIMIT (...) will be on $result[$n - 2];
>
> How should I overcome this problem?
>
>
> 2009/8/21 Daevid Vincent <dae...@daevid.com>
>
> > -----Original Message-----
>> > From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se]
>> >
>> > If you're using MySQL, you can try mysql_field_name()
>> > and see if it gets you anywhere. I don't think it works
>> > on empty results though.
>>
>>
>> FYI. It will.
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> --
> Use ROT26 for best security
>



-- 
Use ROT26 for best security

--- End Message ---
--- Begin Message --- I'd like to get everyone's opinion on a good PHP shopping cart. We need something that will handle a lot of similar items and can be geared for an industrial site selling products from different manufacturers. It needs to be PCI compliant and able to handle at least 5 sub-category levels. I'd also prefer to have it _not_ display the items until after you've drilled down to the final sub- category.

The cart needs to be rock solid and should look professional. We're not looking for wizz-bang, look-at-me fancy. We're selling commercial items here, not women's shoes. (My apologies to the women on the list. =;)

        Real world experience, hearsay, or just gut reactions are all welcome.

Thanks for your help,
Frank

--- End Message ---
--- Begin Message ---
On Fri, 2009-08-21 at 08:06 -0700, sono...@fannullone.us wrote:
>       I'd like to get everyone's opinion on a good PHP shopping cart.  We  
> need something that will handle a lot of similar items and can be  
> geared for an industrial site selling products from different  
> manufacturers.  It needs to be PCI compliant and able to handle at  
> least 5 sub-category levels.  I'd also  prefer to have it _not_  
> display the items until after you've drilled down to the final sub- 
> category.
> 
>       The cart needs to be rock solid and should look professional.  We're  
> not looking for wizz-bang, look-at-me fancy.  We're selling commercial  
> items here, not women's shoes. (My apologies to the women on the  
> list.  =;)
> 
>       Real world experience, hearsay, or just gut reactions are all welcome.
> 
> Thanks for your help,
> Frank
> 
The only e-commerce site I've worked on was based on OSCommerce. It's
pretty good, easy to integrate new functionality into, and not too much
trouble to style up to look the way you want with CSS.


Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
do I understand the doc right, that magic methods do exist in any object?
creating one (like __set() ) ovewrites the standard one?



--- End Message ---
--- Begin Message ---
I think not, but why don't we ask this to PHP ?

<?php

class Foo{}
$foo = new Foo;

var_dump(
    method_exists( $foo, '__set' )
);
?>

*<< __set()* is run when writing data to inaccessible members. >>
http://php.net/__set

So, I think that when you write data to an non-existent member php will
first try is the object has an __set method, if not it'll raise a Fatal
Error

example 1:
<?php
Class Test{
 }

$t = new Test;
$t->a = 'b'; # <-- add public property
print_r( $t );

example 2:
<?php
Class Test{
    private $a;
}

$t = new Test;
$t->a = 'b'; # <-- fatal error

example 3:
<?php
Class Test{
    private $a;

    function __set($name, $value)
    {
        echo $name, ' <- ', $value, PHP_EOL;
    }
}

$t = new Test;
$t->a = 'b'; # <-- trigger __set

example 4:
<?php
Class Test{
    public $a;
    private $c;
    function __set($name, $value)
    {
        echo $name, ' <- ', $value, PHP_EOL;
    }
}

$t = new Test;
$t->a = '1'; # <-- set the public property (don't trigger __set)
$t->b = '2'; # <-- trigger __set (property does not exists)
$t->c = '3'; # <-- trigger __set (property is private)

print_r( $t );


On Fri, Aug 21, 2009 at 12:45 PM, Ralph Deffke <ralph_def...@yahoo.de>wrote:

> do I understand the doc right, that magic methods do exist in any object?
> creating one (like __set() ) ovewrites the standard one?
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
Whoa! I didn't even know you could use a switch statement like that. In 20
years of coding, I've never ever used a switch like that first "if/else"
style. PHP never ceases to amaze me in it's flexibility (and ability to
shoot yourself in the foot ;-p ) 

And remember, all your base are belong to Adam.

> -----Original Message-----
> From: Adam Randall [mailto:randa...@gmail.com] 
> Sent: Thursday, August 20, 2009 11:20 PM
> To: Keith
> Cc: php-gene...@lists.php.net
> Subject: Re: [PHP] Is there limitation for switch case: 
> argument's value?
> 
> I've never understood why people use switch statements like this as in
> reality you are using it more like an if/else block, but anyway.
> 
> The reason why your code is not working is that you are passing into
> the switch the value of 0, or false, which means that when any of
> those $sum == N conditionals comes up as false (say $sum == 8 ), then
> that is what is returned because they match up. In PHP's eyes, 0 ==
> false in switch statements.
> 
> To fix your code, change the switch( $sum ) to switch( true ):
> 
> switch( true )
> {
>       case ($sum == 8):
>               echo "sum=8\n";
>               break;
>       case ($sum == 7 || $sum == 6):
>               echo "sum=7 or 6\n";
>               break;
>       case ($sum == 2 || $sum == 1):
>               echo "sum=2 or 1\n";
>               break;
>       case ($sum == 0):
>               echo "sum=0\n";
>               break;
>       default:
>               echo "sum=3/4/5\n";
>               break;
> }
> 
> Or, write your switch like this:
> 
> switch( $sum )
> {
>       case 8:
>               echo "sum=8\n";
>               break;
>       case 6:
>       case 7:
>               echo "sum=7 or 6\n";
>               break;
>       case 1:
>       case 2:
>               echo "sum=2 or 1\n";
>               break;
>       case 0:
>               echo "sum=0\n";
>               break;
>       default:
>               echo "sum=3/4/5\n";
>               break;
> }
> 
> Regards,
> 
> Adam.
> 
> On Thu, Aug 20, 2009 at 8:40 PM, 
> Keith<survivor_...@hotmail.com> wrote:
> > Hi,
> > I encounter a funny limitation here with switch case as below:
> > The value for $sum is worked as expected for 1 to 8, but not for 0.
> > When the $sum=0, the first case will be return, which is "sum=8".
> > Is there any limitation / rules for switch case? Thanks for advice!
> >
> > Keith
> >
> > $sum=0;
> > switch($sum)
> > {
> >   case ($sum==8):
> >   echo "sum=8";
> >   break;
> >       case ($sum==7 || $sum==6):
> >       echo "sum=7 or 6";
> >       break;
> >   case ($sum==2 || $sum==1):
> >   echo "sum=2 or 1";
> >   break;
> >       case 0:
> >       echo "sum=0";
> >       break;
> >   default:
> >   echo "sum=3/4/5";
> >   break;
> > }
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> 
> -- 
> Adam Randall
> http://www.xaren.net
> AIM: blitz574
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--- End Message ---
--- Begin Message ---
Hello,

on 08/18/2009 05:37 AM leledumbo said the following:
> Usually, a website gives preview of its articles by extracting some of the
> first characters. This is easy if the article is a pure text, but what if
> it's a HTML text? For instance, if I have the full text:
> 
> <p>
>   bla bla bla
>   <ul>
>     <li>item 1</li>
>     <li>item 2</li>
>     <li>item 3</li>
>   </ul>
> </p>
> 
> and I take the first 40 characters, it would result in:
> 
> <p>
>   bla bla bla
>   <ul>
>     <li>item
> 
> As you can see, the tags are incomplete and it might break other texts below
> it (I mean, other than this preview). I need a way to solve this problem.

You may want to try these HTML parser classes. They can parse (and even
validate) HTML and return an array of tag or data elements. You can use
it to pick the first tags and data you. Then you you the RewriteElement
function to regenerate the HTML.

http://www.phpclasses.org/secure-html-filter

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---

Reply via email to