php-general Digest 28 Mar 2004 09:29:14 -0000 Issue 2672

Topics (messages 181617 through 181625):

Convert string and char in unicode format
        181617 by: edwardspl.ita.org.mo

slow script
        181618 by: Luis Gustavo Faccioni Barcellos
        181619 by: electroteque
        181620 by: Galen

Measurement Problem
        181621 by: Karl Timmermann
        181623 by: Jim Kaufman
        181624 by: Galen

mysql table field choices
        181622 by: Andy B

Re: isset() and !=NULL
        181625 by: Dimiter Naydenov

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 ---
Dear All,

How to control php / freetds to convert data ( query / insert )  to
unicode format ?

Thank for you rhelp !

Edward.

--- End Message ---
--- Begin Message --- Hi all.

I am developing a system using php 4.3.2 + apache 1.3.29. The db is a mssql msde (we’re going to mysql, but not yet due to some internal reasons). All things are running in a local, standalone station, because we had to use the app on line and off line states. The off-line one should have all stuff, so. It just connect to internet to send a data replication. The stations are windows 98.

The problem is: I have to run this stuff in small boxes, like some pentium 200mhz with 64-80mb ram, and in these machines the system is very slow. The html page takes about 70 seconds to be showed in the browser. I saw cpu and ram, and are all normal, even the mssql. Just the apache activity goes up to 70% cpu. We notice that while the php is running, anything happens and suddenly(after ~70 seconds) the page arises. Our php code is a kind of big, about 160kb, and the html is generated equally big. I am going to break the jscript stuff it in some small peaces, but will not help to much, I guess.

Well, if someboddy could point out me a way, a tip or a tool to discover what the script is doing while I am waiting its response, or just an ideia, I would really thank you.

Gustavo
--- End Message ---
--- Begin Message ---
> 200mhz with 64-80mb ram, and in these machines the system is very 
> slow. 

Sorry dude you just answered your question.

Also aparantly ODBC is slow.

--- End Message ---
--- Begin Message --- Gustavo,

1) Read the manual - though I can understand how you might have missed this:
http://us2.php.net/manual/en/function.microtime.php


Basically, there's a function based on microtime that does benchmarking. This is vital to timing your script. Use it extensively. If you're not sure where to start, break your script into chunks and figure out where most of your time is being spent.

2) Evaluate where time is being spent. If it's on database-access-bound portions, not a lot you can do from the PHP-end.

3) Evaluate the remainder of your code. In many tight loops (many iterations, not a lot of actual processing per iteration), particularly those modifying arrays, I get much better performance using while() or for() loops instead of foreach() generally. Obviously, this isn't always applicable, but I have found few ways to optimize GD image manipulations while I've found plenty for tight loops, so I'm only giving you suggestions on what I know.

4) Consider some overall performance enhancing stuff. Like the Zend Optimizer (free) which can sometimes help a lot, sometimes not at all. Also I'd say turckmmcache or something like that, but I'm pretty sure there's no Windows 98 version.

5) Evaluate your code. 160 KB (kilobytes, I'm assuming) is a pretty huge amount of PHP code for data replication. I hope that lots of it is content-type things and not all PHP commands, otherwise I would guess (though I could be wrong - some applications are very complex) that you are not coding efficiently. Very few of my projects even approach 160 KB of pure PHP, even things as massive as a complete online store creation and management application I developed not too long ago.

Good luck! Re-post to php-general if you have further questions!

-Galen

On Mar 27, 2004, at 1:43 PM, Luis Gustavo Faccioni Barcellos wrote:

Hi all.
I am developing a system using php 4.3.2 + apache 1.3.29. The db is a mssql msde (we’re going to mysql, but not yet due to some internal reasons). All things are running in a local, standalone station, because we had to use the app on line and off line states. The off-line one should have all stuff, so. It just connect to internet to send a data replication. The stations are windows 98.
The problem is: I have to run this stuff in small boxes, like some pentium 200mhz with 64-80mb ram, and in these machines the system is very slow. The html page takes about 70 seconds to be showed in the browser. I saw cpu and ram, and are all normal, even the mssql. Just the apache activity goes up to 70% cpu. We notice that while the php is running, anything happens and suddenly(after ~70 seconds) the page arises. Our php code is a kind of big, about 160kb, and the html is generated equally big. I am going to break the jscript stuff it in some small peaces, but will not help to much, I guess.
Well, if someboddy could point out me a way, a tip or a tool to discover what the script is doing while I am waiting its response, or just an ideia, I would really thank you.
Gustavo

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

I am working on a PHP/MySQL solution to have a webpage where users can rate cigars. I ran into a problem though. One variable that exists is the length of the cigar. In the cigar world, the lengths are usually written like 6 1/8" or 155 mm or 4 15/16" or 125 mm. I don't want to make the length column in the database be a string with data like "6 1/8"" in it, because as the user submits cigars, different users could type it a different way, screwing up searches that are searching by length. I also want to have a real time metric conversion as well.

So my question is, how should I do this? Should I have a float column with the lengths as mm and it converts it to inches? If so, then how would I convert 155.57500mm to 6 1/8", or 155mm to 6 1/8". It's hard to explain, but I can't come up with a good solution. Please ask if you need clarification.

Any help is much appreciated!

Thanks!
Karl

--- End Message ---
--- Begin Message ---
On Sat, Mar 27, 2004 at 07:55:31PM -0700, Karl Timmermann wrote:
> Hi,
> 
> I am working on a PHP/MySQL solution to have a webpage where users can 
> rate cigars. I ran into a problem though. One variable that exists is 
> the length of the cigar. In the cigar world, the lengths are usually 
> written like 6 1/8" or 155 mm or 4 15/16" or 125 mm. I don't want to 
> make the length column in the database be a string with data like "6 
> 1/8"" in it, because as the user submits cigars, different users could 
> type it a different way, screwing up searches that are searching by 
> length. I also want to have a real time metric conversion as well.
> 
> So my question is, how should I do this? Should I have a float column 
> with the lengths as mm and it converts it to inches? If so, then how 
> would I convert 155.57500mm to 6 1/8", or 155mm to 6 1/8". It's hard to 
> explain, but I can't come up with a good solution. Please ask if you 
> need clarification.
> 
> Any help is much appreciated!
> 
> Thanks!
> Karl
> 

How about a drop down menu with valid lengths in them? That way you can control
what the user enters.

-- 
Jim Kaufman
Linux Evangelist
public key 0x6D802619
http://www.linuxforbusiness.net
---
If you can't learn to do it well, learn to enjoy doing it badly.
                -- Ashleigh Brilliant

--- End Message ---
--- Begin Message --- How about a MySQL table, like you're saying, with the lengths?

Two columns: English and Metric.
Then just do a select metric where english = 6 1/8 (my pseudo-SQL) with MySQL and get the length. I suspect there are only a limited number of standard lengths and this would work nicely.


You could also do a standard mathematical metric-english conversion and then round to the nearest five. That might do the trick also, it would require less data input but there is the slight chance (you'd have to check examples) that you'll find some instance in which it produces the incorrect number. The trickier part will be going in the opposite direction, although that too is manageable.

Good luck!

-Galen

On Mar 27, 2004, at 6:55 PM, Karl Timmermann wrote:

Hi,

I am working on a PHP/MySQL solution to have a webpage where users can rate cigars. I ran into a problem though. One variable that exists is the length of the cigar. In the cigar world, the lengths are usually written like 6 1/8" or 155 mm or 4 15/16" or 125 mm. I don't want to make the length column in the database be a string with data like "6 1/8"" in it, because as the user submits cigars, different users could type it a different way, screwing up searches that are searching by length. I also want to have a real time metric conversion as well.

So my question is, how should I do this? Should I have a float column with the lengths as mm and it converts it to inches? If so, then how would I convert 155.57500mm to 6 1/8", or 155mm to 6 1/8". It's hard to explain, but I can't come up with a good solution. Please ask if you need clarification.

Any help is much appreciated!

Thanks!
Karl

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




--- End Message ---
--- Begin Message ---
just a short one here... what would be the best type of field for a combo box that 
looks like this:

<select name="month" accesskey="m">
<option value="">---pick a month---</option>
<option value="1">January</option>
<option value="2">February</option>
....
</select>
and the same thing with the year...

was thinking either int(2)  for the month and int(4) for the year but would enum(1, 2, 
3, 4...12) be better for the month and enum(2004, 2005, 2007....) be better for the 
year?? dont know what one of those would be better/faster...

and was thinking of timestamp(14) for the result of this function:

/* StartTime: create a timestamp
parameters:
$day: text representation of the day of the month.
examples: "next week", "third monday", "fourth saturday", and so on
$month: valid month number of the year. valid values are 1-12 (without the leading 0).
$year: any valid 4 digit year between 1970 and 2038
discription:
StartTime(string day, int month, int year);
return values: if successful returns a valid timestamp in the form of the total number 
of seconds between jan 1, 1970 and the time created. otherwise returns false if 
failed.*/

function StartTime($day, $month, $year) {
if(!empty($day) && !empty($month) && !empty($year)){
//convert $day, $month, and $year into a valid timestamp
$time= strtotime($day, mktime(0,0,0,$month,1,$year));
return $time; }
else {
return false; }}

--- End Message ---
--- Begin Message ---
David Risner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]> On Fri, 26 
Mar 2004 10:40:43 -0800, "Marcjon Louwersheimer"
> <[EMAIL PROTECTED]> said:
> > Is there an easier way to do
> > isset($variable) AND $variable != NULL
> > ? I use this alot in my if statements, and I was wondering if there's an
> > easier way to do it, maybe with a single function? Oh and another
> > question... how does if ($variable) work? When does it evaluate true?
> 
> Check out the is_null function.  Itd seems to combine the two.
> 
> http://www.php.net/manual/en/function.is-null.php
>    and
> http://www.php.net/manual/en/language.types.null.php#language.types.null.syntax

As Rasmus noted, (!empty($var)) is a complete aquivalent to (isset($var) && $var != 
null). I ran some more extensive tests which show the following:

class MyClass
{
  var $field = 123;
  function MyClass() {}
}

1. $x = null;
2. $y = 0;
3. $z = '';
4. $w = 'xyz';
5. $t = 123;
6. $o = new MyClass();
7. // $v is not set
--------------------------------
1. isset($x) && $x != NULL: []
2. isset($y) && $y != NULL: []
3. isset($z) && $z != NULL: []
4. isset($w) && $w != NULL: [1]
5. isset($t) && $t != NULL: [1]
6. isset($o) && $o != NULL: [1]
7. isset($v) && $v != NULL: []
--------------------------------
1. isset($x): []
2. isset($y): [1]
3. isset($z): [1]
4. isset($w): [1]
5. isset($t): [1]
6. isset($o): [1]
7. isset($v): []
--------------------------------
1. !empty($x): []
2. !empty($y): []
3. !empty($z): []
4. !empty($w): [1]
5. !empty($t): [1]
6. !empty($o): [1]
7. !empty($v): []
--------------------------------
1. is_null($x): [1]
2. is_null($y): []
3. is_null($z): []
4. is_null($w): []
5. is_null($t): []
6. is_null($o): []
Notice: Undefined variable: v in c:\web\test.php on line 62
7. is_null($v): [1] 

Also, as you see is_null($var) throws a notice when the variable is not defined.

Hope this helps ;)

Regards,
Dimiter

--- End Message ---

Reply via email to