php-general Digest 10 Sep 2006 20:19:11 -0000 Issue 4340
Topics (messages 241558 through 241565):
Re: FUNCTION TO CHECK IMAGE
241558 by: tedd
241562 by: Christopher Weldon
How could I make the browser to send a command to a cash register...
241559 by: Man-wai Chang
241560 by: Alex Turner
Re: Newbie question about <?= ?>
241561 by: Al
241563 by: Satyam
241564 by: Jon Anderson
Date maths
241565 by: Dave Goodchild
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:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
At 12:49 AM -0700 9/10/06, BBC wrote:
Hi all.
I'm having a problem regarding image handling. Sometimes an image
can be showed in browser normally (in my computer) but when I
upload it into my site that image is not valid, so there is an issue
in my getimagesizes() function.
Is there any function to recover such problem? I used
"if(file_exists($image_path))" but it couldn't solve the problem.
Input would be appreciated
How are you uploading your image?
What is reporting your image is not valid?
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
BBC wrote:
> Hi all.
> I'm having a problem regarding image handling. Sometimes an image can be
> showed in browser normally (in my computer) but when I
> upload it into my site that image is not valid, so there is an issue in my
> getimagesizes() function.
> Is there any function to recover such problem? I used
> "if(file_exists($image_path))" but it couldn't solve the problem.
> Input would be appreciated
>
> Best Regards
> ============BBC============
> **o<0>o**
>
- From what it sounds like you are doing, you are uploading a file through
some form, then manipulating it's size. Is this correct? What happens
when you stop manipulating it's size and try to view just the uploaded
file?
- --
Christopher Weldon, ZCE
President & CEO
Cerberus Interactive, Inc.
[EMAIL PROTECTED]
979.739.5874
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFBDkiZxvk7JEXkbERArmiAJwLuA2Kk52/uhT6y8ptKEi/D6nkWQCcDa2M
R0uKdIwEaPBGBc14AoZQzo4=
=epdR
-----END PGP SIGNATURE-----
--- End Message ---
--- Begin Message ---
to open its drawer?
--
.~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 6.06) Linux 2.6.17.13
^ ^ 21:43:01 up 1 day 2:37 0 users load average: 0.02 0.03 0.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk
--- End Message ---
--- Begin Message ---
Man-wai Chang wrote:
> to open its drawer?
>
That 100% depends on how the cash register works. Is it an NT cash
register, or an propitiatory one? Is it rs232 or on a network?
Basically, find out how the cash register can be controlled, then make a
php script that can fire that control.
If you find out more about the register we might be able to help a
little more ;-)
Cheers
AJ
--
www.deployview.com
www.nerds-central.com
www.project-network.com
--- End Message ---
--- Begin Message ---
Mike Borrelli wrote:
Good day,
While I've been using php for more than a little while now, I've never
understood why the use of the "<?= ...?>" short tag is noted "to be
avoided".
Or rather, I understand that there's an option to disable it, and that's
why it's noted in this way, but I don't understand why it's disabled?
What's gained by writing <?php echo some_function(); ?> over <?=
some_function(); ?>
Thanks in advance.
Cheers,
Mike
Structurally, there is a far better way to compile your html pages. This approach is easier to design and debug and it
is faster since it sends one complete packet instead of one for every short tag. And, it saves using ob_start() and
ob_flush().
Consider:
$report= '';
$report .= function() [or whatever]
..... repeat as necessary to assemble your complete page.
Then simply
echo $report;
--- End Message ---
--- Begin Message ---
----- Original Message -----
From: "Al" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Sunday, September 10, 2006 5:52 PM
Subject: [PHP] Re: Newbie question about <?= ?>
Mike Borrelli wrote:
Good day,
While I've been using php for more than a little while now, I've never
understood why the use of the "<?= ...?>" short tag is noted "to be
avoided".
Or rather, I understand that there's an option to disable it, and that's
why it's noted in this way, but I don't understand why it's disabled?
What's gained by writing <?php echo some_function(); ?> over <?=
some_function(); ?>
Thanks in advance.
Cheers,
Mike
Structurally, there is a far better way to compile your html pages. This
approach is easier to design and debug and it is faster since it sends one
complete packet instead of one for every short tag. And, it saves using
ob_start() and ob_flush().
Consider:
$report= '';
$report .= function() [or whatever]
..... repeat as necessary to assemble your complete page.
Then simply
echo $report;
Actually, in my experience, that is not the case, my e-mail from more than a
year ago must be somewhere there in the archives, but what you sugest is not
the fastest.
The fastest is to escape out of php (with a ?> ) for the longer invariable
parts of immutable HTML. Stepping out from PHP and in again is handled by
the lexical scanner, it doesn't even reach the parser level so, for all
effects, the PHP interpreter is basically frozen at the point before the ?>
was found. For the sake of completeness, the ?> is translated as a ; for the
parser so it ends any statement that could have been left open, but it does
not bother the parser at all for all the rest of the characters found until
a <?php tag (or equivalent) is found. If the lexer didn't issue a ; for a
?>, the following code would be valid:
echo 'This ' , ?> is <?php 'not valid';
For the variable parts, the best is to issue as little echos as possible
with its arguments separated by commas, not with dots. Most people don't
realize that echo taks a list of arguments, a list separated by commas.
Thus, in the ratings, from best to worst, it goes:
echo '<p>' , $something, '</p>';
echo "<p>$something</p>"
echo '<p>' . $something . '</p>';
echo '<p>'; echo $something; echo '</p>';
The reason for this is that generating a single string either from variable
interpolation as in the second case or by concatenating the arguments, as in
the third, requires a lot of memory handling for the strings and its
intermediate and final results. Some of it might be delayed until the page
is served so the time the garbage collector takes to clean it up might not
be fully reflected in the processing time of a single page, but it does
affect the overall throughput of the server. Notice also that I have used
single quotes whenever possible, which is slightly faster since the parser
has much less to look for within it.
Finally, the first option is the fastest just as a C++ iostream or a Java
StringBuffer are faster than plain strings: since you know you will only
append to the end of them, the characters echoed go into a much more
efficient character buffer instead of a more complex string which has to be
available for all sorts of string operations.
Satyam
--- End Message ---
--- Begin Message ---
Al wrote:
Structurally, there is a far better way to compile your html pages.
This approach is easier to design and debug and it is faster since it
sends one complete packet instead of one for every short tag. And, it
saves using ob_start() and ob_flush().
Consider:
$report= '';
$report .= function() [or whatever]
..... repeat as necessary to assemble your complete page.
Then simply
echo $report;
I thought I'd look into this, because I'm a bit of a performance nut - I
like my code to run as fast as possible at all times. I wrote up a
quick buffer v.s. direct "benchmark" for this, and the winner is clear:
direct output is much faster. (If my example below isn't what you
meant, please let me know. I'm always happy to hear new ways to
improve my code.)
Best of 3 runs with apache bench (concurrency 10, 1000 requests total):
Direct output: 582 requests a second
Buffer var: 286 requests a second
I believe the margin would get wider with real-world usage, as the
buffer variable would increase in size. My test code is copied below.
jon
--- "Direct output": testecho.php ---
<html>
<head>
<style type="text/wastespacetosimulateastylesheet">
style1 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style2 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style3 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style4 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
</style>
</head>
<body><table>
<?php for ($x=0;$x<1000;$x++) { ?>
<tr><td>X is <?= $x ?></td></tr>
<?php } ?>
</table></body>
</html>
--- "Buffered output": testbuffer.php ---
<?php
$buffer = '
<html>
<head>
<style type="text/wastespacetosimulateastylesheet">
style1 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style2 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style3 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
style4 {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
f = 6;
}
</style>
</head>
<body><table>';
for ($x=0;$x<1000;$x++) {
$buffer .= "<tr><td>X is $x</td></tr>";
}
$buffer .= '</table></body>
</html>';
echo $buffer;
?>
--- End Message ---
--- Begin Message ---
Hi all. I am in the midst of creating a national online events directory (ie
evening classes, coffee mornings, yard sales etc). The user is able to enter
one-off events or regular events (daily, weekly, monthly) and each event
entered makes up one record in the events table in the db (mysql). People
are then able to enter a start and end date and the system will show all
events that meet their criteria (category, postcode within a certain
radius).
My problem is with repeating events. My thinking at the moment is to utilise
a calendar table, which contains event id as a foreign key and relevant
dates. All dates are held in the database as timestamps.
So, when an event-holder enters a repeating event, the main event details
are held in the events table, and all the relevant dates for the event (they
specify the first date of the event and the last date it is to be held) are
entered into the calendar table by increment (ie timestamp intervals by 24
hours, 7 days or monthly, and I know monthly is going to be tricky as it is
a fluctuating interval).
Has anyone out there had to deal with a similar problem, and if so do you
have any advice. This is going to take time so I will be patient and
continue, and welcome any suggestions. Many thanks and I can post code to
specific requests.
--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk
--- End Message ---