Re: [PHP] what would a c extension buy me

2006-03-13 Thread Ben Litton
Something that is chiefly bottlenecked at the database isn't going to be  
improved enough at the C level to be worth the trouble. Always optimize  
where it's slow. Database design and indexing helps. Minimizing  
unnecessary queries, writing good ones, helps too.


Once you get to the point that your code is the problem, you should look  
into your algorithms to see if they're as fast as they should be before  
you dive into C. A crappy algorithm will run like crap in any language. I  
had a program in C run in three minutes which was, in my estimation,  
crappy. I re-worked it and used a more sensible algorithm and it now runs  
in less than a second. Obviously it wasn't the language.


In the end maybe an extension will be the way to go for you, depending on  
your needs, but do everything else you can first.


Just my opinion,
Ben

On Mon, 13 Mar 2006 08:04:53 -0500, Jochem Maas [EMAIL PROTECTED]  
wrote:



...


word,def,wordid,pos,posn,wordsize,syn from  korean_english  where word
like '운전할 %'  order by wordsize desc


oh would you look at this
you're ordering by WORDSIZE.
stick an index on WORDSIZE!!!




http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html


In some cases, MySQL cannot use indexes to resolve the ORDER BY,


note 'In Some Cases'.

so stick an index on WORDSIZE and find out.


although it still uses indexes to find the rows that match the WHERE
clause. These cases include the following:

The key used to fetch the rows is not the same as the one used in the
ORDER BY:

SELECT * FROM t1 WHERE key2=constant ORDER BY key1;

2)



you have an iceballs' chance in hell that I'm going to even read
the 500+ lines of code that followed here ... let alone try to
optimize it. ;-)




it was just a 40 line summary of 550 lines of code 


ah, talk about being caught out :-)
regardless a 40line summary won't cut it either - you have to take
the block as a whole.





questions i may deem myself to answer:


) i get this:
[EMAIL PROTECTED] mysql]# tail -f /var/lib/mysql/mysqld_query.log   out

[EMAIL PROTECTED] mysql]# cat out | wc -l
15910 --- that's line count


how many queries?


15, 910 queries


so roughly (15 * 60) seconds to run 15,000+
queries and do the processing? that doesn't actually
sound so bad.





things already taken care of:
1)


  9795 Query   select
word,def,wordid,pos,posn,wordsize,syn from  korean_english where word
like '운전할'  order by wordsize desc


in cases when you are not using the wildcard tokens (percentage signs)
try changing the query to use something like:

... word = '운전할' ...



your suggestion and a line from the query_log match exactly.


2)


snip


then, it sends each token to CallmatchThis (line 14) which calls
matchThis (line 27 - 47 below)
matchThis may be called twice (2 sql queeries)
(line 51) select * where word = '$token' and another  (take that, but  
if

it's not there  issue the next sql )
(line 55) select * where word like '$token%';


Dont do SELECT * - always explicitly specify the fields you want.



that was just a paraphrase. the previous email points to the line number
of the code summary


never paraphrase code - you only end up with smart ass comments like  
mine!


have you reordered you fields in the db yet? adn made as many VARCHARs as
possible into CHARs?








--+
| korean_english | CREATE TABLE `korean_english` (
 `wordid` int(11) NOT NULL auto_increment,
 `word` varchar(130) default NULL,
 `syn` varchar(190) default NULL,
 `def` blob,
 `posn` int(2) default '1',
 `pos` varchar(13) default '1',
 `submitter` varchar(25) default NULL,
 `doe` datetime NOT NULL default '-00-00 00:00:00',
 `wordsize` tinyint(3) unsigned default NULL,
 PRIMARY KEY  (`wordid`),
 KEY `word_idx` (`word`),
 KEY `wordid_idx` (`wordid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |


reorder the fields so that the VARCHARS are at the end of the
table (and the BLOB field at the very, very end of the table).

also change VARCHARs to CHARs where you can.



++-
---
-





1 function MainLoop()







--

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



[PHP] Re: Two version of PHP in single server

2005-11-29 Thread Ben Litton
You can do this if you register a different add-type. Say php5 for the php  
5.1 pages and just php for the regular ones. You may (I can't recall) have  
to install one as mod_php and the other as a cgi. There are surely guides  
on the internet to help you get both running simultaneously.


On Mon, 28 Nov 2005 01:37:02 -0500, J.F.Kishor  
[EMAIL PROTECTED] wrote:



Hi,

I have  a query, can we run  two versions of PHP  in linux 7.2
server.

I want  to use PHP 4.x  for one application and  PHP 5.1.0 for
another application in the same server.

Do  I need to  do some  configuration changes  to set  the php
path. To  look up different  versions based on the  request of
the application.



Regards,
- JFK
kishor
Nilgiri Networks




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: protect password?

2005-11-04 Thread Ben Litton
I'm not sure if there's a way around this, though there's a few simple  
precautions you can take. You can put a function that returns the resource  
in an include file outside of the public html folders, which helps a  
little bit. It's also always good to give the least permission possible  
and to only allow connections from localhost.


Now I know this isn't exactly what you asked, but someone will probably  
come along shortly and offer something more in line.


Ben

On Fri, 04 Nov 2005 15:36:47 -0500, Bing Du [EMAIL PROTECTED] wrote:


Hello,

Some functions need you to provide username and password, for instance
odbc_connect.  Even though the username/password just has minimum access
privileges to the resource, putting it there in clear text in a script  
gives
me heartburn.  How do people handle username/password in such kind of  
cases?

I'm sure there must be some way to store critical information in some
encrypted format but it's still readable to scripts for authentication
purpose.  But don't know how.  Any ideas or pointer would be greatly
appreciated.

Bing




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: getting rid of bad characters

2005-10-31 Thread Ben Litton
Check in the comments section of ths page: http://us3.php.net/htmlentities  
. You're not the first person to have this problem.

Ben


On Mon, 31 Oct 2005 10:30:49 -0500, Dan McCullough  
[EMAIL PROTECTED] wrote:



I having been looking for some snippet to help me with changing MS
Word double, quotes, single quotes and other characters to acceptable
HTML safe characters.  The problem comes about when the people using
the forms paste large articles from Word into the form, I do a normal
check and add slashes but lately they have been getting lazy and using
the special characters from Word.




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] GUID or any other unique IDs

2005-10-25 Thread Ben Litton
While not ideal, you could do a select on a db. MS SQL and MySQL both have  
functions to generate unique id's and I imagine the other databases do as  
well. While running a SELECT uuid() and hitting the database for each  
one of these things is annoying, it is one possible pseudo-solution.


On Tue, 25 Oct 2005 06:47:26 -0400, Denis Gerasimov  
[EMAIL PROTECTED] wrote:



Hello Jasper,


$unique_id = sha1( uniqid( mt_rand(), true ) );

which should be very unique and suitable for most purposes.


I really need millions of unique IDs - hashing is not suitable for this  
task

(I think so) :-(. Any more ideas?

Is there a PHP extension or an external library for generating GUIDs?

Have a great day,

Denis S Gerasimov
Web Developer
Team Force LLC

Web:   www.team-force.org
RU  Int'l:   +7 8362-468693
email:[EMAIL PROTECTED]




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: Email Validation built-in? RFC

2005-10-24 Thread Ben Litton
You could certainly write an extension to do so. That's what I did (mostly  
I was writing one for another purpose and added a function I stole from  
O'Reilly. You can find the C code I used here:  
http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html.  
It's pretty clever (If you're used to doing things the PHP/regex way) and  
while I haven't benchmarked it, I'd imagine it is pretty fast.


There are lots of php extension tutorials out there, but if you want me to  
wrap it for you I probably could. I'm sure though that the many php regex  
solutions out there are probably 'good enough' for your needs, and I  
haven't tested that C code on some of the stranger e-mail addresses out  
there in existance.


Ben



On Fri, 21 Oct 2005 22:58:38 -0400, Richard Lynch [EMAIL PROTECTED] wrote:


Given:

It is unacceptable to reject perfectly valid email addresses, no
matter how arcane. [Like mine. :-)]

The CORRECT RegEx for validating an email is 3 pages long, and
performance in PHP would probably not be so good...

In today's Security-conscious world, data validation is a requirement.

The (relatively) recent changes in domain names that allow UTF
(Unicode?) characters.

Checking MX records is not reliable at all.

Forcing users to respond to email is A) burdensome to real users in
many cases, and B) no real barrier to halfway intelligent fake users.

... would it not make sense for there to be a BUILT-IN PHP function of
a TRUE email syntactic validation?

So at least one KNOWS that the email is a valid construct, before you
even try (if you try at all) to make sure that a person actually
checks it at least once in their life.

Currently, email syntax validation is being done in very limited
fashion, if not outright wrong by rejecting what actually ARE valid
email addresses in about 10,000,000 PHP scripts by users who don't
have any realistic options to truly do it right because who can
really live with that 3-page Regex in their PHP code?

Yes, in the past, I may have come down squarely on the opposite side
of this topic, but I've changed my mind.

I believe PHP needs a built-in syntactically CORRECT email validation
function, vetted and tested by professionals, instead of the mess we
now have.

PLEASE do not point me to any existing email validation code unless
you believe it is not only 100% correct and complete with RFC
definitions of syntactically valid email.  Not interested.  I've
already seen them, and been burned by them.





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: Inserting NULL Integer Values

2005-10-18 Thread Ben Litton
Either cast your empty ints (which should make it zero) or do an if  
(!isset($variable)) { $variable = 'NULL'; }


Ben

On Tue, 18 Oct 2005 12:15:41 -0400, Shaun [EMAIL PROTECTED]  
wrote:



Hi,

Up to this point in time I used to construct my insert statements like  
this


$qid = mysql_query('INSERT INTO MYTABLE (
column1,
column2,
   ) VALUES (
'.$value1.',
'.$value2.'
   )');

However I understand it is better to remove the quote marks around an  
insert
if the column type is an integer. This is easy to do, however if the  
$value

is empty it causes a mysql error. Has anyone encountered this and found a
solution?

Thanks for your advice




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: Inserting NULL Integer Values

2005-10-18 Thread Ben Litton
Yes, but NULL is a special thing to MySQL. If you don't quote 'NULL' it  
just means 'empty' to mySQL. If your database schema allows NULLS (it's  
optional), your insert will go through.


On Tue, 18 Oct 2005 13:10:32 -0400, Shaun [EMAIL PROTECTED]  
wrote:



Hi Ben,

Thanks for your reply, woudn't that insert a string with a value  
of'NULL';?


Ben Litton [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

Either cast your empty ints (which should make it zero) or do an if
(!isset($variable)) { $variable = 'NULL'; }

Ben

On Tue, 18 Oct 2005 12:15:41 -0400, Shaun  
[EMAIL PROTECTED]

wrote:


Hi,

Up to this point in time I used to construct my insert statements like
this

$qid = mysql_query('INSERT INTO MYTABLE (
column1,
column2,
   ) VALUES (
'.$value1.',
'.$value2.'
   )');

However I understand it is better to remove the quote marks around an
insert
if the column type is an integer. This is easy to do, however if the
$value
is empty it causes a mysql error. Has anyone encountered this and  
found a

solution?

Thanks for your advice




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] Re: Inserting NULL Integer Values

2005-10-18 Thread Ben Litton
Good explanation but I think he wanted to avoid quoting the integers. I  
may be wrong, but I think not quoting integers is a decent practice  
because it makes it easier to port your SQL over to a different database  
if you later decide you must do so. Of course he could just add a single  
quote to both sides of the string, whether it is empty or not, but if he  
wants to go without any single quotes, he'll have to use NULL or a  
numberic value for every column.


Everything you said is of course correct and a bit less lazy than my  
explanation. I would just say that if he didn't want any single quotes at  
all he could just replace your elses of $value = ' . $value2 . '; with  
$value = (int) $value1; OR $value1 = intval($value1).


If he decies not going to use quotes, it's probably a good idea to make  
sure it's really an number or it'll break the query. He could also do an  
is_numeric($value1) to make sure it really is one, but if you don't mind  
converting an errant string to a zero, casting works fine.


As for the double quotes inside the parser thing, I do that too out of  
laziness on occasion, but try not to. If the OP wants to stick to the  
gospel and employ quotes he could make your else $value1 = '\'.$value1.\'';


_Ben

On Tue, 18 Oct 2005 13:42:19 -0400, [EMAIL PROTECTED] wrote:

What Ben said is correct, but I'd like to elaborate so you know why it's  
correct.


The INSERT statement you're trying to end up with is:

INSERT INTO MYTABLE (column1, column2) VALUES ('somevalue1',  
'somevalue2')



I'm not sure why it wouldn't work if you ended up with:
INSERT INTO MYTABLE (column1, column2) VALUES ('', '')

That should work.  You can set it so you can't have NULL, but dont know  
of anything that tells the database not to accept '' as a value (barring  
triggers or other things that check on insert).


Anyway, assuming that the first example is what youre going for, then it  
sounds like this is what you want if the first value is empty:


INSERT INTO MYTABLE (column1, column2) VALUES (NULL, 'somevalue2')

So I might try something like this:

$value1 = ;
$value2 = somevalue;

if (is_empty($value1)) {
  $value1 = NULL;
} else {
  $value1 = ' . $value1 . ';
}

if (is_empty($value2)) {
  $value2 = NULL;
} else {
  $value2 = ' . $value2 . ';
}

$qid = mysql_query(INSERT INTO MYTABLE (column1, column2) VALUES  
($value1, $value2));


That way, if it's empty, you'll get NULL, otherwise you'll get  
'somevalue'.


I use double quotes () PHP variable values (yeah, I know.. some people  
have issues because it makes everything inside interpret..blah blah..)  
and use single quotes (') for SQL stuff.  Looks like you do the  
opposite.  Whatever works for you.


Good luck!

-TG

= = = Original message = = =

Either cast your empty ints (which should make it zero) or do an if
(!isset($variable))  $variable = 'NULL';

Ben

On Tue, 18 Oct 2005 12:15:41 -0400, Shaun [EMAIL PROTECTED]
wrote:


Hi,

Up to this point in time I used to construct my insert statements like
this

$qid = mysql_query('INSERT INTO MYTABLE (
column1,
column2,
   ) VALUES (
'.$value1.',
'.$value2.'
   )');

However I understand it is better to remove the quote marks around an
insert
if the column type is an integer. This is easy to do, however if the
$value
is empty it causes a mysql error. Has anyone encountered this and found  
a

solution?

Thanks for your advice



___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] Re: Inserting NULL Integer Values

2005-10-18 Thread Ben Litton

You're using two =='s for your assignment.

On Tue, 18 Oct 2005 15:15:59 -0400, Shaun [EMAIL PROTECTED]  
wrote:



Hi all,

Thanks for your replies, rather than check each vaule by name I am  
trying to

produce a more dynamic solution:

foreach ($_POST as $key = $value) {
  if ($value == '') {
$_POST[$key] == 'NULL';
  }
}

I was expecting $_POST[$key] to be the same as $key, however this isnt  
the

case:

$key = city
$_POST[$key] = London
$value = London

Any ideas?

Richard Lynch [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

On Tue, October 18, 2005 12:42 pm, [EMAIL PROTECTED] wrote:

That should work.  You can set it so you can't have NULL, but dont
know of anything that tells the database not to accept '' as a value


Any database, other than MySQL, is *NOT* going to accept '' as an
integer value.

Because '' is not an integer by any stretch of the imagination.

If you don't care about ever porting your application to something
other than MySQL, then you can IGNORE the advice to not use '' on
integers.

If there's ANY possibility that some day somebody might maybe wanna
use a different database with your application, then don't confuse
strings with integers.

Actually, it might be better for your own
education/sanity/comprehension/documentation/code to not confuse
strings and integers with '' around integers in the SQL, but if
everything ELSE is good in your code, and it's always going to be
MySQL then it's fine.

Note that:

$value2 = 'NULL'; //PHP $value2 is a string

$query = insert into (integer_field) values ($value2);
//PHP $query is a string, but...

The place-holder in $value2 will be just: NULL

No quotes.

No apostrophes.

Not a string.

NULL

SQL NULL value representing no value

--
Like Music?
http://l-i-e.com/artists.htm




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: Recommended Reading?

2005-10-18 Thread Ben Litton
I liked Schlossnagle's 'Advanced PHP Programming'  
http://www.amazon.com/exec/obidos/tg/detail/-/0672325616/qid=1129664190/sr=8-1/ref=pd_bbs_1/002-6178615-3953615?v=glances=booksn=507846


It has a little primer on a variety of things but is for the php5 user.  
You might also want to read a book called Code Complete


http://www.amazon.com/exec/obidos/tg/detail/-/0735619670/qid=1129664509/sr=8-1/ref=pd_bbs_1/002-6178615-3953615?v=glances=booksn=507846

It's probably written more for the C/C++/Java crowd, but is meant to  
mostly be language neutral. It gives some great pointers on software  
construction. Some seems fairly obvious, but if you're self-taught (like I  
am) then you're sure to take a few things away from it.


Ben

On Tue, 18 Oct 2005 14:43:36 -0400, Alan Lord [EMAIL PROTECTED]  
wrote:



Hi all,

Forgive this long diatribe, a bit off-topic I know, but it might
stimulate a good discussion...

I have built a few small apps in PHP before and, whilst they work, I
can't but help feeling that I go about the whole thing the WRONG way...

I am not a professional software person (far from it) but I am
reasonably competent in most things technical. I trained in
Electronics, build my own PCs and Linux systems from scratch, have used
- just for fun - Java, Delphi, Visual Basic, PHP and a little C/C++.

I am now wanting to write my own application (using PHP of course) to do
something really useful. And I am looking for some recommendations on
reading [books or links] about how to design my application and how to
think about the design in it's abstract form before I start writing
code.

Normally I end up writing little bits of code to solve small problems
and then sort of kludging them together to do something useful.

I would really like to try and go about this one the RIGHT way.

Thanks in advance.

Al




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] Uploaded CSV - database

2005-10-17 Thread Ben Litton
Actually I think fgetcsv will work with any valid file pointer and at  
least in PHP 5, the streams implementation will allow you to use a variety  
of protocols to create the stream.


http://us2.php.net/manual/en/wrappers.php

I understand that it isn't even too teribbly difficult to implement your  
own stream if one isn't already to your liking, but I'm afraid I haven't  
found need to go beyond the simple read-a-file-from disk style operation.


Ben

On Mon, 17 Oct 2005 11:45:04 -0400, Jim Moseby [EMAIL PROTECTED]  
wrote:



-Original Message-
From: Brian Dunning [mailto:[EMAIL PROTECTED]
Sent: Monday, October 17, 2005 11:39 AM
To: php-general@lists.php.net
Subject: Re: [PHP] Uploaded CSV - database


It looks like all of those tips will easily cover me for the latter
half of the operation. Any tips on how to get the uploaded CSV file
into memory in order to attack it with fgetcsv()? I'd rather
not ever
have to actually write the file to the server's disk.

Thanks!



If you are using the standard file upload facilities, your file is  
being
written to disk when it is being uploaded.  As far as I can tell,  
fgetcsv()

will only read a file from disk:

?php // from the manual
$row = 1;
$handle = fopen (test.csv,r);
while ($data = fgetcsv ($handle, 1000, ,)) {
$num = count ($data);
print p $num fields in line $row: br\n;
$row++;
for ($c=0; $c  $num; $c++) {
print $data[$c] . br\n;
}
}
fclose ($handle);
?

If you are instead using a socket connection to receive the file in a  
stream

from the client, you could assign it to a string variable, and use
explode().

These are fairly uncharted territories for me, so others will likely have
better answers.

JM




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



[PHP] Re: Array within array

2005-09-30 Thread Ben Litton

I would do something like

$fp = fopen($file_location, 'r');
while (!$fp) {
$csv_line = fgetcsv($fp);
//insert line into database here after appropriate validation and cleaning
}

On Fri, 30 Sep 2005 06:29:11 -0400, Chris [EMAIL PROTECTED] wrote:


Greetings PHP community,

I have a CSV text file which I need to use to update existing DB
records.

So I have the following :

$array_file = file(path/to/file);

file() creates an array comprising each line of the file, but if each
line contains 20 or so CS values, how do I go about reading each line
and updating the db.

Pseudo code :
=
$array_file = file(path/to/file);
while (explode(',',$file_array))
{
  do update on db for each line of array
}
=

Any pointers ?

--
Chris Blake
Cell: 082 775 1492
Work: +27 11 880 2825
Fax : +27 11 782 0841
Mail: [EMAIL PROTECTED]

Immortality -- a fate worse than death. -- Edgar A. Shoaff




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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