php-general Digest 10 Dec 2008 12:31:19 -0000 Issue 5837
Topics (messages 284398 through 284409):
Re: file_exists and wildcard/regex
284398 by: Stut
284399 by: German Geek
284402 by: Per Jessen
284403 by: Per Jessen
usort for sorting an array of objects
284400 by: German Geek
284406 by: Stut
284409 by: German Geek
Re: MSSQL_CONNECT problem
284401 by: Andrew Ballard
restrict fsockopen spam etc.
284404 by: Andre Hübner
284407 by: Carlos Medina
284408 by: mike
Re: Include directive..
284405 by: dele454
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 ---
On 9 Dec 2008, at 23:24, Daniel Kolbo wrote:
Maciek Sokolewicz wrote:
Daniel Kolbo wrote:
What is the preferred method with php to test and see if a file
[pattern] exists?
For example, i only need to search in one directory, that may have
any number of files named such as afile1.txt, afile2.txt,
afile3.txt, .... And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
I want to see if any such file 'family' exists. That is, i want
to see if there is any file named bfile[1-9][0-9]+.txt. I don't
care which bfile number exists, i just want to know if any bfile
exists.
I hope this is clear enough, if not let me know.
thanks,
dK
glob()
http://www.php.net/glob
How portable is glob?
How fast is glob? Being that it searches through the entire
filesystem, this could potentially take a long time (like if i have
wildcards early in the filepath pattern and lots of matches)
correct? If my file variations (wildcards) are just at the end of
of the filepaths and i don't have more than 1000 files in the
directory then will I most likely be 'alright' with glob (in terms
of time)? I have probably spent more time now 'considering' the
time implications of glob, than glob actually would consume when
operating...
Thanks for the quick response/solutions.
dK
Glob works on all platforms.
Glob does suffer from performance issues above a certain number of
files, and this can be system dependant. If you're unsure how many
files it may return you'd be better using opendir/readdir.
Not sure where you got the idea that glob searches the entire file
system, but it's limited to either the current working directory or
the directory you specify. So if your PHP file is in /var/www/htdocs
and you do glob('*.txt') you'll get all .txt files in /var/www/htdocs.
And if you do glob('/tmp/*.txt') you'll get all .txt files in /tmp.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
On Wed, Dec 10, 2008 at 1:13 PM, Stut <[EMAIL PROTECTED]> wrote:
>
> On 9 Dec 2008, at 23:24, Daniel Kolbo wrote:
>
> Maciek Sokolewicz wrote:
>>
>>> Daniel Kolbo wrote:
>>>
>>>> What is the preferred method with php to test and see if a file
>>>> [pattern] exists?
>>>>
>>>> For example, i only need to search in one directory, that may have any
>>>> number of files named such as afile1.txt, afile2.txt, afile3.txt, .... And
>>>> also, bfile1.txt, bfile2.txt, bfile3.txt, ...
>>>> I want to see if any such file 'family' exists. That is, i want to see
>>>> if there is any file named bfile[1-9][0-9]+.txt. I don't care which bfile
>>>> number exists, i just want to know if any bfile exists.
>>>>
>>>> I hope this is clear enough, if not let me know.
>>>>
>>>> thanks,
>>>> dK
>>>>
>>>>
>>> glob()
>>>
>>> http://www.php.net/glob
>>>
>> How portable is glob?
>> How fast is glob? Being that it searches through the entire filesystem,
>> this could potentially take a long time (like if i have wildcards early in
>> the filepath pattern and lots of matches) correct? If my file variations
>> (wildcards) are just at the end of of the filepaths and i don't have more
>> than 1000 files in the directory then will I most likely be 'alright' with
>> glob (in terms of time)? I have probably spent more time now 'considering'
>> the time implications of glob, than glob actually would consume when
>> operating...
>>
>> Thanks for the quick response/solutions.
>> dK
>>
>
> Glob works on all platforms.
>
> Glob does suffer from performance issues above a certain number of files,
> and this can be system dependant. If you're unsure how many files it may
> return you'd be better using opendir/readdir.
>
> Not sure where you got the idea that glob searches the entire file system,
> but it's limited to either the current working directory or the directory
> you specify. So if your PHP file is in /var/www/htdocs and you do
> glob('*.txt') you'll get all .txt files in /var/www/htdocs. And if you do
> glob('/tmp/*.txt') you'll get all .txt files in /tmp.
>
> -Stut
>
> --
> http://stut.net/
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I wrote my own little function for a regex pattern match on files:
class FileHandle {
public static function copyReg($srcDir, $destDir, $regEx, $mkdir =
false) {
// ensure we have the right dir separator /(unix) \(win) and not at
the end
$srcDir = rtrim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR,
$srcDir), DIRECTORY_SEPARATOR);
$destDir = rtrim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR,
$destDir), DIRECTORY_SEPARATOR);
//echo "DEST: ". $destDir ." END";
if ($mkdir && !is_dir($destDir)) mkdir($destDir, 0777, true); //make
dir if not exists and mkdir
if ($handle = opendir($srcDir)) {
while (false !== ($file = readdir($handle))) {
//echo "$file\n";
preg_match($regEx, $file, $matches);
if ($file != '.' && $file != '..' && count($matches) > 0) {
//print("<pre>$regEx $srcDir $file \n=".
print_r($matches,true));
copy($srcDir . DIRECTORY_SEPARATOR . $file,
$destDir . DIRECTORY_SEPARATOR . $file);
}
}
return true;
}
return false;
}
}
Hope that helps. Don't know how good this will perform.
--
Tim-Hinnerk Heuer
http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
>
> I'm not sure how glob works in the guts, but I know it is dog-slow for
> large numbers of files (or maybe just large numbers of results).
>
I'm not sure what the context of this was, but the speed of searching a
directory with a large number of files, e.g. 100,000s, also depends a
lot on the filesystem.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> If you're on a Linux system, you could look at ls and the regular
> expressions it lets you use with it. You could exec out and get the
> returned results. Also, as it's a system call, it should be very
> speedy.
'ls' is just a plain binary (/bin/ls), not a system call. The regex
functionality is part of the shell, usually bash.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Hi Guys,
I need to sort an array of objects. I found this ( at a url that didnt let
me send this msg... ) and I would know how to do it, but I believe there
might be a cleaner, more elegant way to do it. In Java, you just need to
implement the interface Comparable and provide a method called compareTo (as
far as i remember) and then you can use one of the many sorting algorithms
generically on objects that are comparable...
Anyway, I didn't find something like that for PHP. Since I'm using symfony,
I had a bit of a play with the objects at hand and simply did a
sort($arrayOfObjects) and it did sort them by the id. Just wondering where
it got the information on what to sort on (not quite) correctly for my case?
Thanks for your interest.
--
Tim-Hinnerk Heuer
http://www.ihostnz.com -- Web Design, Hosting and free Linux Support
--- End Message ---
--- Begin Message ---
On 10 Dec 2008, at 04:15, German Geek wrote:
I need to sort an array of objects. I found this ( at a url that
didnt let
me send this msg... ) and I would know how to do it, but I believe
there
might be a cleaner, more elegant way to do it. In Java, you just
need to
implement the interface Comparable and provide a method called
compareTo (as
far as i remember) and then you can use one of the many sorting
algorithms
generically on objects that are comparable...
Anyway, I didn't find something like that for PHP. Since I'm using
symfony,
I had a bit of a play with the objects at hand and simply did a
sort($arrayOfObjects) and it did sort them by the id. Just wondering
where
it got the information on what to sort on (not quite) correctly for
my case?
I'm confused. The function you need is the one you mention in the
subject. All you need to do is create a function that compares two of
the objects, in whatever way you need it to, and returns -1, 0 or 1.
The pass that to the usort function - it doesn't care what type of
thing is in the array. Full details available at http://php.net/usort.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
On Wed, Dec 10, 2008 at 10:27 PM, Stut <[EMAIL PROTECTED]> wrote:
> On 10 Dec 2008, at 04:15, German Geek wrote:
>
>> I need to sort an array of objects. I found this ( at a url that didnt let
>> me send this msg... ) and I would know how to do it, but I believe there
>> might be a cleaner, more elegant way to do it. In Java, you just need to
>> implement the interface Comparable and provide a method called compareTo
>> (as
>> far as i remember) and then you can use one of the many sorting algorithms
>> generically on objects that are comparable...
>>
>> Anyway, I didn't find something like that for PHP. Since I'm using
>> symfony,
>> I had a bit of a play with the objects at hand and simply did a
>> sort($arrayOfObjects) and it did sort them by the id. Just wondering where
>> it got the information on what to sort on (not quite) correctly for my
>> case?
>>
>
> I'm confused. The function you need is the one you mention in the subject.
> All you need to do is create a function that compares two of the objects, in
> whatever way you need it to, and returns -1, 0 or 1. The pass that to the
> usort function - it doesn't care what type of thing is in the array. Full
> details available at http://php.net/usort.
I just ment to say it would be nice to have it like in Java or C# where you
can implement an interface, called Comparable and define a function in the
class called compareTo which returns an integer smaller, equal or greater
than 0 by which elements can generically be sorted by in a collection. Since
PHP has arrays (hash maps) as the primary collection type, and they are very
good for storing sets or other collections, it would be nice to have a sort
function that would look, if the elements of the array have a compareTo
method (implement the Comparable interface), and if they do, then sort with
that. I find it a bit surprising that such a well designed programming
language doesn't have such a useful feature. I guess one could use one of
the gazillion libraries out there to do the same thing. Also, one could
argue that this further checking would slow down functions that are
primarily used for sorting strings. However, the answer could be also in the
ArrayObject class which is in php natively. Only it should implement all the
array functions that are there anyway, which shouldnt be too hard to do for
the PHP PL developers. Some more in depth documentation of that class would
also be helpful.
Anyway, I found a not perfect, but good enough solution:
Implement a static compare function in the class of the object and put a
function in my library, that is simply called myTools::sort that will get
the object class of the first element of the array (if there is one) and
sort according to the compare method implemented in that class (if it
exists), otherwise just use sort. The compare method takes the parameters as
self:
public class AClass { // implements Comparable {
public static function compare(self $obj1, self $obj2) {
return strcmp($obj1->prop1, $obj2->prop1); // e.g.
}
}
That way I will get an exception if there is an object in the array which
does not have that class, but i can live with that. At least i'll get an
exception and not another funny error, because the parameters are self,
right?
It might be better to define an interface called Comparable with that
method, but was not really necessary for my case.
Just a few thoughts to maybe improve PHP in the future. Hopefully there will
be a lot of interfaces and objects for collection types at some stage in PHP
natively, although that might clutter the namespace and could be realised
with libraries. What are your thoughts?
--
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
On Tue, Dec 9, 2008 at 3:41 PM, David Stoltz <[EMAIL PROTECTED]> wrote:
> Yes, I'm using a valid SQL account. I've tried putting both versions of
> "ntwdblib.dll" in the php directory, and the system32 directory (not at once
> of course), and I get the same error.
>
> I've pretty much tried everything I've read....the kicker is I can access the
> SQL Server fine by using ADO in PHP. It's only when I try mssql_connect that
> the connection fails....
>
> The whole reason I don't use ADO is because the queries don't stand up to SQL
> injection...So I wanted to use mssql_connect with "mssql_bind" so I can do
> parameterized queries....
>
> Do you have any other thoughts?
>
> Thanks!
>
I've had decent luck so far with the SQL Server Driver for PHP
published by Microsoft since Jason pointed me to it a while ago.
Andrew
--- End Message ---
--- Begin Message ---
Hello List,
in last times i recognize that some scripts/formmailer of customers get abused
by spammers.
Some scripts avoid to use smtp-server and do smtp-dialog by its own using
fsockopen etc.
Problem ist that if mails are sent by fsockopen directy to other servers they
not occur in server-maillog.
Only way to find them is viewing accesslog, bit it is really hard to make
relations between entries in accesslog
and spamreports from other servers.
My question is if there is a way to restrict fsockopen to use not port 25 or a
kind of logging which makes entries if fsockopen is used.
This gets more and more to a problem for us but we do not want to disable
fsockopen completely at the moment.
Is there a way to realize this?
Thanks,
Andre
--- End Message ---
--- Begin Message ---
Andre Hübner schrieb:
Hello List,
in last times i recognize that some scripts/formmailer of customers get abused
by spammers.
Some scripts avoid to use smtp-server and do smtp-dialog by its own using
fsockopen etc.
Problem ist that if mails are sent by fsockopen directy to other servers they
not occur in server-maillog.
Only way to find them is viewing accesslog, bit it is really hard to make
relations between entries in accesslog
and spamreports from other servers.
My question is if there is a way to restrict fsockopen to use not port 25 or a
kind of logging which makes entries if fsockopen is used.
This gets more and more to a problem for us but we do not want to disable
fsockopen completely at the moment.
Is there a way to realize this?
Thanks,
Andre
Hallo Andre,
i dont know why you use sockets to send a mail but it is save to solve
your problems with a algorithm and architecture. I think you can use a
capcha to get the control again over your script.
Regards
Carlos
--- End Message ---
--- Begin Message ---
I think there was a proposed change to allow php to log mail calls. I
was disappointed to see it did not get put in to php yet though. Would
help to pinpoint scripts being abused, especially in shared
environments.
On Dec 10, 2008, at 1:43 AM, Carlos Medina <[EMAIL PROTECTED]>
wrote:
Andre Hübner schrieb:
Hello List,
in last times i recognize that some scripts/formmailer of customers
get abused by spammers.
Some scripts avoid to use smtp-server and do smtp-dialog by its own
using fsockopen etc.
Problem ist that if mails are sent by fsockopen directy to other
servers they not occur in server-maillog.
Only way to find them is viewing accesslog, bit it is really hard
to make relations between entries in accesslog
and spamreports from other servers.
My question is if there is a way to restrict fsockopen to use not
port 25 or a kind of logging which makes entries if fsockopen is
used.
This gets more and more to a problem for us but we do not want to
disable fsockopen completely at the moment.
Is there a way to realize this?
Thanks,
Andre
Hallo Andre,
i dont know why you use sockets to send a mail but it is save to
solve your problems with a algorithm and architecture. I think you
can use a capcha to get the control again over your script.
Regards
Carlos
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Am having this error in the apache log files WHat does it imply really. I
have no idea. Am trying to run Zf but my pages are all blank so i was
wondering if this has anything to do with it. Thanks will appreciate any
help:
[Wed Dec 10 11:15:03 2008] [warn] [client 190.30.20.221] mod_include:
Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
[Wed Dec 10 11:15:05 2008] [error] [client 190.30.20.221] File does not
exist: /usr/local/apache/htdocs/administrator
[Wed Dec 10 11:15:05 2008] [warn] [client 190.30.20.221] mod_include:
Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
[Wed Dec 10 11:15:08 2008] [error] [client 190.30.20.221] File does not
exist: /usr/local/apache/htdocs/administrator
[Wed Dec 10 11:15:08 2008] [warn] [client 190.30.20.221] mod_include:
Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
[Wed Dec 10 11:15:10 2008] [error] [client 190.30.20.221] File does not
exist: /usr/local/apache/htdocs/administrator
[Wed Dec 10 11:15:10 2008] [warn] [client 190.30.20.221] mod_include:
Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
[Wed Dec 10 11:15:12 2008] [error] [client 190.30.20.221] File does not
exist: /usr/local/apache/htdocs/administrator
[Wed Dec 10 11:15:12 2008] [warn] [client 190.30.20.221] mod_include:
Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed
-----
dee
--
View this message in context:
http://www.nabble.com/Include-directive..-tp20893857p20930853.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---