php-general Digest 21 Dec 2008 05:51:26 -0000 Issue 5857
Topics (messages 284884 through 284902):
Re: Require error
284884 by: Jochem Maas
Re: filter function vs regular expression
284885 by: Richard Heyes
284886 by: Nathan Nobbe
284888 by: Robert Cummings
284890 by: Per Jessen
284891 by: Richard Heyes
284894 by: Stan Vassilev | FM
Re: Using php in custom built http server
284887 by: Nathan Nobbe
284892 by: mike
284897 by: Mr. Gecko
Re: curl_exec return value
284889 by: phphelp -- kbk
Image Resizing
284893 by: Stephen Alistoun
284895 by: Ólafur Waage
284896 by: Ashley Sheridan
imap_rfc822_parse_adrlist problem
284898 by: Ben Stuyts
284899 by: Manuel Lemos
284900 by: Manuel Lemos
Passing var from one page to itself
284901 by: Aslan
Re: search for person by comparing his data with data in mysql
284902 by: Andrew Ballard
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 ---
Wolf schreef:
> ---- Kyle Terry <[email protected]> wrote:
>> On Fri, Dec 19, 2008 at 9:43 AM, Wolf <[email protected]> wrote:
>>
>>> Bottom Post
>>>
>>> ---- sean greenslade <[email protected]> wrote:
>>>> No. The file is called testing.php and it is trying to include sql.inc
>>>>
>>>> On Fri, Dec 19, 2008 at 12:36 PM, Kyle Terry <[email protected]> wrote:
>>>>
>>>>>
>>>>> On Fri, Dec 19, 2008 at 9:28 AM, sean greenslade <
>>> [email protected]>wrote:
>>>>>> So, I have this code in a php file called testing.php:
>>>>>> $incl = '/webs/www.zootboy.com/sl/sql.inc';
>>>>>> if(!is_readable($incl)) die('ERROR: MySQL Include file does not
>>>>>> exist??!?');
>>>>>> require $incl or die('MySQL page not found. Unable to continue.');
>>>>>>
>>>>>>
>>>>>> When I run the code in command line, it outputs this:
>>>>>>
>>>>>> [r...@localhost ~]# php -f /webs/www.zootboy.com/sl/testing.php
>>>>>> PHP Warning: require(1): failed to open stream: No such file or
>>> directory
>>>>>> in /webs/www.zootboy.com/sl/testing.php on line 13
>>>>>> PHP Fatal error: require(): Failed opening required '1'
>>>>>> (include_path='/var/php/inc/') in /webs/
>>> www.zootboy.com/sl/testing.php on
>>>>>> line 13
>>>>>>
>>>>>> I have no idea what's going on. All the files have 777 perms.
>>>>>>
>>>>>> --
>>>>>> --Zootboy
>>>>>>
>>>>> Are you trying to require itself?
>>> Change your line to:
>>> require('$incl') or die('File not found');
>>>
>>> Require can be dork about things like this, I normally wind up handling to
>>> fiddle with the coding for them.
>>>
>>> Wolf
>>>
>> Actually, single quoted will be string literal. He would need to encase them
>> in double quotes so the parser knows it might be looking for a variable.
>> require("$incl") is what he wants.
>>
>
> See! I told you I always have problems with those! :)
>
> Normally I'm not so literal though.
>
> so yeah:
> require("$incl");
> include("$incl");
brilliant, stick a variable containing a string into an interpolated and
otherwise empty string.
require($incl);
... the quotes are a complete waste of time/cpu.
>
> I prefer the includes over the requires, but that is personal preference.
>
> Wolf
>
--- End Message ---
--- Begin Message ---
> i'm reading a book about PHP and i was wondering why regular expressions are
> so often used to check format of variables or emails while the function
> filter exists since version 5.2.
That's not so long.
> What are the plus of regular expression while checking variable format ?
They' more versatile. Far more in the case of PCRE.
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated December 5th)
--- End Message ---
--- Begin Message ---
On Sat, Dec 20, 2008 at 9:06 AM, Richard Heyes <[email protected]> wrote:
> > i'm reading a book about PHP and i was wondering why regular expressions
> are
> > so often used to check format of variables or emails while the function
> > filter exists since version 5.2.
>
> That's not so long.
>
> > What are the plus of regular expression while checking variable format ?
>
> They' more versatile. Far more in the case of PCRE.
to elaborate, in general, the filter extension should be faster than
corresponding preg_* calls from user space. why? b/c, they essentially are
compiled calls to pcre (in many cases) for specific cases, such as email.
check out the C for filter_validate_email(), its pretty simple:
void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
{
/* From
http://cvs.php.net/co.php/pear/HTML_QuickForm/QuickForm/Rule/Email.php?r=1.4*/
const char regexp[] =
"/^((\\\"[^\\\"\\f\\n\\r\\t\\b]+\\\")|([\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4]
pcre *re = NULL;
pcre_extra *pcre_extra = NULL;
int preg_options = 0;
int ovector[150]; /* Needs to be a multiple of 3 */
int matches;
re = pcre_get_compiled_regex((char *)regexp, &pcre_extra, &preg_options
TSRMLS_CC);
if (!re) {
RETURN_VALIDATION_FAILED
}
matches = pcre_exec(re, NULL, Z_STRVAL_P(value), Z_STRLEN_P(value), 0,
0, ovector, 3);
/* 0 means that the vector is too small to hold all the captured
substring offsets */
if (matches < 0) {
RETURN_VALIDATION_FAILED
}
}
basically all it does is call pcre_exec() on against some email regex, and
the string you want to search from userspace. the difference between that
and a call to preg_match() using the same regex and search string is speed.
the other tradeoff, as richard mentioned is flexibility. since you cant
possibly conjure / write all possible calls to the regex engine, it makes
sense to expose something like the preg_* functions to userspace. that
being said, id recommend wrapping the filter_* calls in your validation code
when & where possible, which is essentially the mantra of php programming in
general anyway (stick to the native functions as much as possible).
-nathan
ps.
ill probly setup a test later to see if my half-baked theory is even
accurate :O
--- End Message ---
--- Begin Message ---
On Sat, 2008-12-20 at 16:22 +0100, Alain Roger wrote:
> Hi,
>
> i'm reading a book about PHP and i was wondering why regular expressions are
> so often used to check format of variables or emails while the function
> filter exists since version 5.2.
> What are the plus of regular expression while checking variable format ?
> thx.
Because then your app would lose all compatibility with versions below
5.2.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
> to elaborate, in general, the filter extension should be faster than
> corresponding preg_* calls from user space. why? b/c, they
> essentially are compiled calls to pcre (in many cases)
There is no or only the tiniest little difference - AFAICT preg_match
and the filter extension both use the same regex caching mechanism. If
the regex has not been compiled, the first call will compile it,
subsequent calls will use the already compiled regex.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
/* From
> http://cvs.php.net/co.php/pear/HTML_QuickForm/QuickForm/Rule/Email.php?r=1.4
> */
Huh. I was under the impression that it did full verification, as
according to RFC (2)822. Not that that's generally necessary, in fact
it's mostly just outdated crap, (the technical term I believe).
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated December 20th)
--- End Message ---
--- Begin Message ---
Huh. I was under the impression that it did full verification, as
according to RFC (2)822. Not that that's generally necessary, in fact
it's mostly just outdated crap, (the technical term I believe).
--
Richard Heyes
That's the problem with the filter extension. It's a black box and you never
know what it checks, or how. Often it validates poor input as is the case
with its URL validation.
Regex means you see what's happening and you have control over it.
I've been using the filter_* validators in some cases, but after inspecting
the C source code of this extension and finding multiple side effects in the
filters I used, I dropped it and went back to regex/strlen/ctype_*/etc.
Regards, Stan Vassilev
--- End Message ---
--- Begin Message ---
On Fri, Dec 19, 2008 at 11:47 PM, mike <[email protected]> wrote:
> Yep Nginx, lighttpd, Zeus it's the only way. Apache has the option and I
> think a lot of people recommend it for various reasons.
>
> I'd recommend nginx over lighttpd :)
>
well now ill have to go scope out nginx :D
anyways, major diff between cgi & libphp should be performance, wherein cgi
should be like waaay slower. but supposedly fastCGI is pretty solid. peep
this thread from a little while back,
http://coding.derkeiler.com/Archive/PHP/comp.lang.php/2007-01/msg00120.html
and it looks like lighttpd supports fastCGI+php, so again, prob a good
source for free working code examples ;D
-nathan
--- End Message ---
--- Begin Message ---
On Sat, Dec 20, 2008 at 9:37 AM, Nathan Nobbe <[email protected]> wrote:
> well now ill have to go scope out nginx :D
>
> anyways, major diff between cgi & libphp should be performance, wherein cgi
> should be like waaay slower. but supposedly fastCGI is pretty solid. peep
> this thread from a little while back,
>
> http://coding.derkeiler.com/Archive/PHP/comp.lang.php/2007-01/msg00120.html
>
> and it looks like lighttpd supports fastCGI+php, so again, prob a good
> source for free working code examples ;D
you can look at nginx or lighttpd for samples of fastcgi.
i think there are some very minor implementation details where one
might be better than another, etc.
fastcgi is good because it does not tie up the webserver itself with a
PHP engine that leaks some memory, but dispatches the request to a
separate entity and allows you to scale them separately.
a webserver like nginx can do much more work even on a single box -
wordpress.com had it pushing 8000 reqs/s of real world load balancing
traffic - and then you can focus on giving fastcgi the resources it
needs, be it more engines on the same box or splitting it apart and
creating a pool of fastcgi engines on N servers...
i'd also recommend php-fpm. it makes configuring php for fastcgi
elegant, adds in multiple options and will soon adaptively spawn the
amount of engines like apache does with webserver
threads/processes/whatever as needed...
--- End Message ---
--- Begin Message ---
Thanks for the suggestions. I'll read on about it and tell you what I
came up with, so if someone else want's to do something similar they
can base it off of what I built.
Here are some replies to what you guys asked
I don't know if I would go open source on this.
I can use c code in Objective-C so yeah I can base it off of Lighttpd
or Nginx
On Dec 20, 2008, at 2:33 PM, mike wrote:
On Sat, Dec 20, 2008 at 9:37 AM, Nathan Nobbe
<[email protected]> wrote:
well now ill have to go scope out nginx :D
anyways, major diff between cgi & libphp should be performance,
wherein cgi
should be like waaay slower. but supposedly fastCGI is pretty
solid. peep
this thread from a little while back,
http://coding.derkeiler.com/Archive/PHP/comp.lang.php/2007-01/msg00120.html
and it looks like lighttpd supports fastCGI+php, so again, prob a
good
source for free working code examples ;D
you can look at nginx or lighttpd for samples of fastcgi.
i think there are some very minor implementation details where one
might be better than another, etc.
fastcgi is good because it does not tie up the webserver itself with a
PHP engine that leaks some memory, but dispatches the request to a
separate entity and allows you to scale them separately.
a webserver like nginx can do much more work even on a single box -
wordpress.com had it pushing 8000 reqs/s of real world load balancing
traffic - and then you can focus on giving fastcgi the resources it
needs, be it more engines on the same box or splitting it apart and
creating a pool of fastcgi engines on N servers...
i'd also recommend php-fpm. it makes configuring php for fastcgi
elegant, adds in multiple options and will soon adaptively spawn the
amount of engines like apache does with webserver
threads/processes/whatever as needed...
--- End Message ---
--- Begin Message ---
Hey - - - - ----- - -
I am new to using cURL, so I would appreciate your help. Fortunately,
I have samples to follow, but the return value is not as I expect.
In short, instead of returning a Resource, it is just returning TRUE.
I have tried setting:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TRANSFERTEXT, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
I have tried these together and separately and in all combinations.
(IOW: flailing blindly)
Any clue what I am doing wrong? (relevant code below)
Ken
Code:
-----------------------------------------------------
$url = $this->cc_submit_post_url;
$ch = curl_init();
// my lines, in any combination
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TRANSFERTEXT, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
// these lines are *supposedly* well-tested
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HEADER, false); // providing a header
manually
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
// The following two options are necessary to properly set up SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
$appl['error_message'] = curl_error($ch);
$return_val = FALSE;
} else {
curl_close($ch);
}
-------------------------------------------
--- End Message ---
--- Begin Message ---
Hi all,
What is the best way in PHP to Resize an Image to a specific width.
For Example I have images in the following sizes:
(1) 200px width and 350px height
(2) 125px width and 220px height
(3) 166px width and 455px height
I want all the images to resize to 100px width but the height adjusts
automatically.
Regards,
Stephen
--
View this message in context:
http://www.nabble.com/Image-Resizing-tp21108753p21108753.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---
--- Begin Message ---
With the built in functions (GD), you can read up on this function:
http://is.php.net/manual/en/function.imagecopyresized.php
If you have Imagick installed, you can read up on this:
http://is.php.net/manual/en/function.imagick-thumbnailimage.php
On Sat, Dec 20, 2008 at 8:38 PM, Stephen Alistoun
<[email protected]> wrote:
>
> Hi all,
>
> What is the best way in PHP to Resize an Image to a specific width.
>
> For Example I have images in the following sizes:
>
> (1) 200px width and 350px height
> (2) 125px width and 220px height
> (3) 166px width and 455px height
>
> I want all the images to resize to 100px width but the height adjusts
> automatically.
>
> Regards,
>
> Stephen
> --
> View this message in context:
> http://www.nabble.com/Image-Resizing-tp21108753p21108753.html
> Sent from the PHP - General mailing list archive at Nabble.com.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Sat, 2008-12-20 at 20:59 +0000, Ólafur Waage wrote:
> With the built in functions (GD), you can read up on this function:
> http://is.php.net/manual/en/function.imagecopyresized.php
> If you have Imagick installed, you can read up on this:
> http://is.php.net/manual/en/function.imagick-thumbnailimage.php
>
> On Sat, Dec 20, 2008 at 8:38 PM, Stephen Alistoun
> <[email protected]> wrote:
> >
> > Hi all,
> >
> > What is the best way in PHP to Resize an Image to a specific width.
> >
> > For Example I have images in the following sizes:
> >
> > (1) 200px width and 350px height
> > (2) 125px width and 220px height
> > (3) 166px width and 455px height
> >
> > I want all the images to resize to 100px width but the height adjusts
> > automatically.
> >
> > Regards,
> >
> > Stephen
> > --
> > View this message in context:
> > http://www.nabble.com/Image-Resizing-tp21108753p21108753.html
> > Sent from the PHP - General mailing list archive at Nabble.com.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
RTFM
http://uk.php.net/manual/en/function.imagecopyresampled.php
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Hi,
Since upgrading to php 5.2.8 I have a problem with
imap_rfc822_parse_adrlist. When I run the example given on the manual
page at http://nl3.php.net/imap_rfc822_parse_adrlist:
$adds = 'ian eiloart <[email protected]>,
[email protected],
blobby,
"ian,eiloart"<[email protected]>,
<@example.com:[email protected]>,
f...@#,
[email protected],
i...@one@two';
$add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
var_export ($add_arr);
I should get:
...
2 =>
class stdClass {
var $mailbox = 'blobby';
var $host = 'example.ac.uk';
},
...
but I get:
...
2 =>
stdClass::__set_state(array(
'mailbox' => 'blobby',
'host' => 'p?a(',
)),
...
So the host part isn't filled in correctly. I have verified this on
two FreeBSD 7 machines. On an older FreeBSD 5 machine with php4 this
works fine. Before the update, I was running php 5.2.6 and there was
no problem either. Any ideas?
Thanks,
Ben
--- End Message ---
--- Begin Message ---
Hello,
on 12/20/2008 09:34 PM Ben Stuyts said the following:
> Hi,
>
> Since upgrading to php 5.2.8 I have a problem with
> imap_rfc822_parse_adrlist. When I run the example given on the manual
> page at http://nl3.php.net/imap_rfc822_parse_adrlist:
>
> $adds = 'ian eiloart <[email protected]>,
> [email protected],
> blobby,
> "ian,eiloart"<[email protected]>,
> <@example.com:[email protected]>,
> f...@#,
> [email protected],
> i...@one@two';
> $add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
> var_export ($add_arr);
>
> I should get:
> ...
> 2 =>
> class stdClass {
> var $mailbox = 'blobby';
> var $host = 'example.ac.uk';
> },
> ...
>
> but I get:
> ...
> 2 =>
> stdClass::__set_state(array(
> 'mailbox' => 'blobby',
> 'host' => 'p?a(',
> )),
> ...
>
> So the host part isn't filled in correctly. I have verified this on two
> FreeBSD 7 machines. On an older FreeBSD 5 machine with php4 this works
> fine. Before the update, I was running php 5.2.6 and there was no
> problem either. Any ideas?
Sometime ago I decided to not use IMAP library functions to parse e-mail
addresses because it was not handling all sorts of addresses as it should.
Nowadays I use an e-mail address parser class written in pure PHP that
comes with this MIME parser class:
http://www.phpclasses.org/mimeparser
--
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 ---
--- Begin Message ---
Hello,
on 12/20/2008 09:34 PM Ben Stuyts said the following:
> Hi,
>
> Since upgrading to php 5.2.8 I have a problem with
> imap_rfc822_parse_adrlist. When I run the example given on the manual
> page at http://nl3.php.net/imap_rfc822_parse_adrlist:
>
> $adds = 'ian eiloart <[email protected]>,
> [email protected],
> blobby,
> "ian,eiloart"<[email protected]>,
> <@example.com:[email protected]>,
> f...@#,
> [email protected],
> i...@one@two';
> $add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
> var_export ($add_arr);
>
> I should get:
> ...
> 2 =>
> class stdClass {
> var $mailbox = 'blobby';
> var $host = 'example.ac.uk';
> },
> ...
>
> but I get:
> ...
> 2 =>
> stdClass::__set_state(array(
> 'mailbox' => 'blobby',
> 'host' => 'p?a(',
> )),
> ...
>
> So the host part isn't filled in correctly. I have verified this on two
> FreeBSD 7 machines. On an older FreeBSD 5 machine with php4 this works
> fine. Before the update, I was running php 5.2.6 and there was no
> problem either. Any ideas?
Sometime ago I decided to not use IMAP library functions to parse e-mail
addresses because it was not handling all sorts of addresses as it should.
Nowadays I use an e-mail address parser class written in pure PHP that
comes with this MIME parser class:
http://www.phpclasses.org/mimeparser
--
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 ---
--- Begin Message ---
Hey there,
I have a problem where I have a simple -script that I am wanting to
pass back to itself three times
1) Symptoms - > 2) Troubleshooting questions 3) Answer to problem
The page is passing the vars from the first page to the second, but the
first pages vars are not passed to the third (but the second page is)
I am using includes for each sectional "page" and passing it back to itself
if($submitted == "")
{
include 'inc/tshoot2-input.php';
}
if($submitted == "symptoms")
{
include 'inc/tshoot2-symptoms.php';
}
if($submitted == "submitted")
{
include 'inc/answers.php';
}
The tool will ultimately be on www.adslgeek.com/troubleshooter/
I have it currently all on one page, but it isn't quite what I was after
..
Any help would be appreciated!
Cheers
ADSL Geek
--- End Message ---
--- Begin Message ---
On Sat, Dec 20, 2008 at 7:01 AM, Jochem Maas <[email protected]> wrote:
> [email protected] schreef:
>> select
>> first_name like '%$first_name%'
>> + 3 * last_name like '%$last_name%'
>> + 7 * email = '$email'
>> as score,
>
> that works?? I guess the expressions (e.g. email = '$email')
> evaluate to bools and are auto-cast to ints.
>
> Im guess there needs to be some parenthesis in there somewhere, no?
>
> anyway nice snippet :-)
>
If it works, it must be a MySQL "feature".
Andrew
--- End Message ---