Tải bản đầy đủ (.pdf) (64 trang)

Tài liệu Simple, Affordable, Reliable PHP / MySQL Web Hosting Solutions docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.38 MB, 64 trang )

TM
NEXCESS.NET Internet Solutions
304 1/2 S. State St.
Ann Arbor, MI 48104-2445
h t t p : / / n e x c e s s . n e t
PHP / MySQL
SPECIALISTS!
Simple, Affordable, Reliable PHP / MySQL Web Hosting Solutions
POPULAR SHARED HOSTING PAC K A G E S
MINI-ME
$
6
95
POPULAR RESELLER HOSTING PACKAGES
500 MB Storage
15 GB Transfer
50 E-Mail Accounts
25 Subdomains
25 MySQL Databases
PHP5 / MySQL 4.1.X
SITEWORX control panel
/mo
SMALL BIZ
$
21
95
2000 MB Storage
50 GB Transfer
200 E-Mail Accounts
75 Subdomains
75 MySQL Databases


PHP5 / MySQL 4.1.X
SITEWORX control panel
/mo
N
EX
R
ESELL
1
$
16
95
900 MB Storage
30 GB Transfer
Unlimited MySQL Databases
Host 30 Domains
PHP5 / MYSQL 4.1.X
NODEWORX Reseller Access
All of our servers run our in-house developed PHP/MySQL
server control panel: INTERWORX-CP
INTERWORX-CP features include:
- Rigorous spam / virus filtering
- Detailed website usage stats (including realtime metrics)
- Superb file management; WYSIWYG HTML editor
INTERWORX-CP is also available for your dedicated server. Just visit
o for more information and to place your order
.
WHY NEXCESS.NET? WE ARE PHP/MYSQL DEVELOPERS
LIKE YOU AND UNDERSTAND YOUR SUPPORT NEEDS!
ORDER TODAY AND GET 10% OFF ANY WEB HOSTING PACKAGE
VISIT HTTP://NEXCESS.NET/PHPARCH FOR DETAILS

Dedicated & Managed Dedicated server solutions also available
Serving the web since Y2K
/mo
N
EX
R
ESELL
2
$
59
95
7500 MB Storage
100 GB Transfer
Unlimited MySQL Databases
Host Unlimited Domains
PHP5 / MySQL 4.1.X
NODEWORX Reseller Access
/mo
C O N T R O L P A N E L
:
php
php
5
php
php
4
NEW! PHP 5 & MYSQL 4.1.X
PHP4 & MySQL 3.x/4.0.x options also available
We'll install any PHP extension you
need! Just ask :)

128 BIT SSL CERTIFICATES
AS
LOW AS $39.95
/ YEAR
DOMAIN NAME REGISTRATION
FROM $10.00
/ YEAR
GENEROUS AFFILIATE PROGRAM
UP TO 100% PAY BACK
PER REFERRAL
30 DAY
MONEY BACK GUARANTEE
FREE DOMAIN NAME
WITH ANY ANNUAL SIGNUP
4.1.x
3.x/4.0.x
1 <?php
2

3 @set_time_limit(3600);

4 // limit it to one hour
of processing

5

6 // “Main” functions
occur here

7


8 DB_Connect(“your_db”);

9

10 $query = “SELECT *,
jobs.job_id as id

11 FROM jobs job, job_
status status

12 WHERE job.job_id =
status.job_id

13 AND status.job_
status = 0

14 ORDER BY job.job_id
ASC LIMIT 1”;

15 // if you want to
process more, then change

16 // or abolish the limit

17

18 if ($recordset = mysql_
query($query))


19 {

20 // if you have a
limit of 1 this can be an
if statement
21 while ($row = mysql_
fetch_array ($recordset))

22 {

23 WorkFunction($row);

24 }

25 }

26 else

27 {

28 // We have nothing to
process

29 exit();

30 }

31

32 function

WorkFunction($fields)

33 {

34 // this is where your
work goes, whatever it may
be
35 // in this case were
going to say that data
comes
36 // from a processing
file database and got into

37 // a destination file

38 // to make a
limitation, we’re saying
that fields must
39 // be less than 100
characters long

40

41 DB_Connect(“your_
db”);

42

43 // set it to “1” to
say the job is underway


44 $sql = “UPDATE job_
status SET job_status = 1

45 WHERE job_id =
“.$fields[‘id’];

46 if( !($result =
mysql_query($sql)) )

47 {

48 die(“problems with
the import job”);

49 }

50

51 $query = “SELECT *
FROM “.$fields[‘processing_
file’];
52 if ($recordset =
mysql_query($query))

53 {

54 while ($row =
mysql_fetch_array
($recordset))

55 {

56 $names = “”;

57 $values = “”;

58 $comma = “”;

59

60 $status =
“Status_Green”;

61 $status_notice =
“”;

62

63 foreach ($row as
$key => $value)

64 {

65 if
(strlen($value) < 100)

66 {

67 $names .=
$comma.$key;


68 $values .=
$comma.”’”.
addslashes($value).”’”;
69 $comma = “,”;

70 }

71 else

72 {

73 $status =
“Status_Yellow”;

74 $status_
notice .= $key.” was too
long; “;
75 }

76 }

77

78 $sql = “INSERT
INTO
“.$fields[‘destination_
file’].

79 “ (“.$names.”)

VALUES (“.$values.”)”;

80 if (!($result =
mysql_query($sql)))

81 {

82 $status =
“Status_Red”;

83 $status_notice
.= “ process failed; “;

84 }

85 $status_notice =
“ ID “.$row[‘id’].” : “

86 $status_notice;

87 write_log_
post($job_id,$status_
notice,$status);
88 $$status++; //
$$status = $green or $red
or $yellow
89

90 // if $pass % 50
= 0 then update import

table and
91 // wipe
statistics

92 $pass++;

93 if (($pass % 50)
== 0)

94 {

95 $sql = “UPDATE
job_status SET

96 Status_Green =
Status_Green + “.$Status_
Green.”,
97 Status_Yellow =
Status_Yellow + “.$Status_
Yellow.”,
98 Status_Red =
Status_Red + “.$Status_
Red.”,
99 processed =
processed + 50

100 WHERE job_id =
“.$fields[‘id’];

101 if( !($result =

mysql_query($sql)) )

102 {

103 die(“problems
with the import job”);

104 }

105 $Status_Green =
0;

106 $Status_Yellow
= 0;

107 $Status_Red =
0;

108 }

109 }

110

111 // set it to “2” to
say the job has been done

112

113 $sql = “UPDATE job_

status SET

114 job_status = 2,

115 Status_Green =
Status_Green + “.$Status_
Green.”,
116 Status_Yellow =
Status_Yellow + “.$Status_
Yellow.”,
117 Status_Red =
Status_Red + “.$Status_
Red.”,
118 processed =
“.(intval($pass) - 1).”

119 WHERE job_id =
“.$fields[‘id’];

120 if( !($result =
mysql_query($sql)) )

121 {

122 die(“123 }

124 $Status_Green = 0;

125 $Status_Yellow = 0;


126 $Status_Red = 0;

127 }

128 }

129

130 function write_log_
post($job_id,$status_
notice,$status)
131 {

132 DB_Connect(“your_
db”);

133

134 $sql = “INSERT INTO
job_log “;

135 $sql .= “(`job_
id`,`status`,`status_
notice`)”;
136 $sql .= “ VALUES “;

137 $sql .= “(‘”.
addslashes($job_id).”’,’”.

138 addslashes($status)

.”’,’”.

139 addslashes($status_
notice).”’)”;

140

141 if ( !($result =
mysql_query($sql)) )

142 {

143 die(“problems with
the import log”);

144 }

145 }

146

147 function DB_
Connect($db_name)

148 {

149 $dbhost = “your_
dbhost”;

150 $dbuser = “db_login”;


151 $dbpass = “db_pass”;

152 $dbc = mysql_
connect($dbhost, $dbuser,
$dbpass)
153 || die 1 <?php

2

3 @set_time_limit(3600);

4 // limit it to one hour
of processing

5

6 // “Main” functions
occur here

7

8 DB_Connect(“your_db”);

9

10 $query = “SELECT *,
jobs.job_id as id

11 FROM jobs job, job_

status status

12 WHERE job.job_id =
status.job_id

13 AND status.job_
status = 0

14 ORDER BY job.job_id
ASC LIMIT 1”;

15 // if you want to
process more, then change

16 // or abolish the limit

17

18 if ($recordset = mysql_
query($query))

19 {

20 // if you have a
limit of 1 this can be an
if statement
21 while ($row = mysql_
fetch_array ($recordset))

22 {


23 WorkFunction($row);

24 }

25 }

26 else

27 {

28 // We have nothing to
process

29 exit();

30 }

31

32 function
WorkFunction($fields)

33 {

34 // this is where your
work goes, whatever it may
be
35 // in this case were
going to say that data

comes
36 // from a processing
file database and got into

37 // a destination file

38 // to make a
limitation, we’re saying
that fields must
39 // be less than 100
characters long

40

41 DB_Connect(“your_
db”);

42

43 // set it to “1” to
say the job is underway

44 $sql = “UPDATE job_
status SET job_status = 1

45 WHERE job_id =
“.$fields[‘id’];

46 if( !($result =
mysql_query($sql)) )


47 {

48 die(“problems with
the import job”);

49 }

50

51 $query = “SELECT *
FROM “.$fields[‘processing_
file’];
52 if ($recordset =
mysql_query($query))

53 {

54 while ($row =
mysql_fetch_array
($recordset))
55 {

56 $names = “”;

57 $values = “”;

58 $comma = “”;

59


60 $status =
“Status_Green”;

61 $status_notice =
“”;

62

63 foreach ($row as
$key => $value)

64 {

65 if
(strlen($value) < 100)

66 {

67 $names .=
$comma.$key;

68 $values .=
$comma.”’”.
addslashes($value).”’”;
69 $comma = “,”;

70 }

71 else


72 {

73 $status =
“Status_Yellow”;

74 $status_
notice .= $key.” was too
long; “;
75 }

76 }

77

78 $sql = “INSERT
INTO
“.$fields[‘destination_
file’].

Features
14

PHP & Oracle
Analysis of this recently announced partnership
and its benefits to the web developer community
by ROBERT MARK
21

Job Management

with PHP & Cron

Discussion on building an admin page
to create and monitor a job queue

with near-real-time status updates

by MIKE DeWOLFE
31

Flying with Seagull
A step-by-step guide for setting up
an example module
by WILLIAM ZELLER and WERNER M. KRAUSS
45

User Management
with Active Directory

Accessing, inserting or altering objects within
the AD structure of Microsoft Windows Server 2003
by CHAD R. SMITH
SPECIAL FEATURE
60

Conference Coverage

Review and analysis of the php|works and web|works
coference held in Toronto, September 14-16, 2005
by PETER B. MacINTYRE

TM
Columns
6

EDITORIAL
8

php|news
10

TIPS & TRICKS
mail() hacks
Redefining and Redirecting
mail()

by BEN RAMSEY
52

TEST PATTERN
To Test is to Fake
How to properly test the whole system
by MARKUS BAKER
57

SECURITY CORNER
Cross Site Scripting
by CHRIS SHIFLETT
64

exit(0);

It’s a Bird! It’s a Plane!
It’s FUD!
by MARCO TABINI
If you want to bring a php-related topic to the attention of the professional php community, whether it
is personal research, company software, or anything else, why not write an article for php|architect?
If you would like to contribute, contact us and one of our editors will be happy to help you hone
your idea and turn it into a beautiful article for our magazine. Visit www.phparch.com/writeforus.php
or contact our editorial team at and get started!
Download this month’s code at:


/>CONTENTS
WRITE FOR US!


T
hose of us in the know have been aware of PHP’s readiness to take on the “enterprise” for
quite a while, now. We’ve built serious applications, we’ve processed millions of dollars
worth of transactions with our favorite language, and we’ve even been heard extolling
PHP’s virtues before management-types.
An all-too-common scene in the office, though, is PHP sneaking in through the
back door. Upper- (or perhaps mid-) management has traditionally favored heavily-marketed, and
“proven” products over non-orthodox, community-built technologies. I once worked for a CTO who
(as the joke went, anyway) would build the next project on whatever platform was advertised on
the last page of his business magazines. Unfortunately, many of the developers (myself included)
were not convinced that the joke was only that—a joke.
Despite—or perhaps thanks to—this lack of technological vision, our “little secret” language
has been making huge inroads into the enterprise, lately. We have a few key players to thank for
this; especially Zend.
Zend’s involvement with PHP is obvious—they are “The PHP Company” after all. They’ve

recently made a few strategic moves that are helping to propel PHP into the minds of corporations,
IT managers, CTOs, and other business-types. As far as I’m concerned, they’ve made four key moves
to promote PHP in this way.
The first two are related (and the first of which is partially covered in this issue): Zend Core
for Oracle, and Zend Core for IBM. Much like large-business’ dislike for non-mainstream software,
they’re often seen shunning open-source database platforms. With Zend actively working with both
Oracle and IBM’s DB2, the PHP database taboo has been lifted. Many corporations have already
deployed systems on Oracle or DB2, and (correctly) see no need to add yet another database
platform to their clusters. (IBM has returned the favor by participating in PHP development—see
PDO_odbc (
/>), the PDO documentation (
/>) and
SDO (
/>).)
The next move on Zend’s part, of enterprise significance, is Marc Andreessen’s recent joining
of Zend’s board of directors. Marc seems to have wholeheartedly accepted PHP as a legitimate
platform for serious web applications, facing the competition of coffee-based languages head on:
“PHP is to 2005 what Java was to 1995.” Those are strong words from a guy with both serious
technology and business credibility.
The last of Zend’s recent moves that I find significant is the recent announcement of the PHP
Collaboration Project, including the Zend Framework. This one has three major enterprise-friendly
parts (again, in my opinion): Engagement with the Eclipse Foundation, a standard development
framework for PHP, and corporation-friendly licensing and license-auditing of the code in the
framework.
There is little information available on Zend’s work with Eclipse, but I’m eager to find out, as
I’m personally an active PHP Eclipse user, and I long for certain features of Zend Studio (especially
debugging). Just as with the database problem above, many companies already have Eclipse
deployed for their (especially Java-) developers.
The framework itself (to which I’ve been invited to participate, but as yet have only lurked
on the mailing list) will hopefully breed a new generation of PHP applications that can avoid the

menial task of form handling (as one example)—see also this month’s continuation of the article
on building applications with the Seagull framework (which exists and is ready to use, today
).
The licensing feature of the framework is particularly beneficial to enterprises who wish to
re-sell applications developed in PHP. The PHP project has been burned by the GPL before (which
is why you won’t find any GPL-licensed extensions in PECL), and even for code licensed under a
BSDish (e.g. PHP) license, there’s always the risk that code being stolen from an unknown source,
without some sort of auditing. Zend provides this with their framework.
All of this to say: not only is PHP ready for the enterprise, but the enterprise is starting to
awaken to this fact. Kudos to the key players for making this happen!
THE ENTERPRISE

AWAKENS
EDITORIAL
Volume 4 - Issue 11
Publisher
Marco Tabini
Editor-in-Chief
Sean Coates
Editorial Team
Arbi Arzoumani
Peter MacIntyre
Eddie Peloke

Graphics & Layout
Aleksandar Ilievski

Managing Editor
Emanuela Corso
News Editor

Leslie Hill

Authors
Marcus Baker, Werner M. Krauß,

Peter B. MacIntyre, Robert Mark,

Ben Ramsey, Chris Shiflett,

Chad R. Smith, Mike DeWolfe,

William Zeller

php|architect (ISSN 1709-7169) is published
twelve times a year by Marco Tabini & Associates,
Inc., P.O. Box 54526, 1771 Avenue Road, Toronto,
ON M5M 4N5, Canada.
Although all possible care has been placed in
assuring the accuracy of the contents of this
magazine, including all associated source code,
listings and figures, the publisher assumes
no responsibilities with regards of use of the
information contained herein or in all associated
material.
php|architect, php|a, the php|architect logo, Marco
Tabini & Associates, Inc. and the Mta Logo are
trademarks of Marco Tabini & Associates, Inc.
Contact Information:
General mailbox:


Editorial:
Subscriptions:

Sales & advertising:
Technical support:

Printed in Canada
Copyright
©
2003-2005
Marco Tabini & Associates, Inc.
All Rights Reserved
OCTOBER 2005 • php|architect •6

×