[PHP] OOP to run sequential SQL queries?

2013-02-17 Thread AmirBehzad Eslami
Dear list,

We have a bunch of SQL-queries, they should be executed in
a sequential order, with a defensive programming style in mind.

We were thinking to implement the solution as Stored Procedures
instead of a PHP solution that runs SQL queries, but an article in
Coding Horro recommendeds to avoid SP for good reasons:

http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html

Now we're going to carry on in PHP, and my experience says that
we should write the solution in a procedural-style, instead of OOP.

Is there any benefit to use OOP in these situations?

Please share your thoughts.

Thanks,
-behzad


[PHP] Apache to serve RESTful requests using PHP

2013-02-09 Thread AmirBehzad Eslami
Dear list,

We're a developing a PHP-driven web service with a RESTful API,
and we have a dedicated Linux server for that with 6GB of RAM.

Since this service will be used by many clients in a concurrent
manner,  we'll face with a high-load on our web-server.  But
web-services are different from web pages, for instance they
don't include images, or in this case we only serve JSON.

I'm wondering what are the recommended configurations for
the Apache web-server in these situations?  Should we disable
keep-avlie?  What about other directives?  Apache is our
bottleneck, and we're trying to optimize it. Should we use nginx instead?

Please let me know your suggestions.

Thank you,
-behzad


Re: [PHP] Apache to serve RESTful requests using PHP

2013-02-09 Thread AmirBehzad Eslami
Bastein,

Response is unique per request, and not cachable.  The app
fetches records from MySQL (say, templates), performs a
process on them, and returns the generated output as JSON.

We were thinking to use Redis to reduce queries against
MySQL, but still Apache will remain as our bottleneck.

On Sun, Feb 10, 2013 at 1:00 AM, Bastien phps...@gmail.com wrote:



 Bastien Koert

 On 2013-02-09, at 11:42 AM, AmirBehzad Eslami behzad.esl...@gmail.com
 wrote:

  Dear list,
 
  We're a developing a PHP-driven web service with a RESTful API,
  and we have a dedicated Linux server for that with 6GB of RAM.
 
  Since this service will be used by many clients in a concurrent
  manner,  we'll face with a high-load on our web-server.  But
  web-services are different from web pages, for instance they
  don't include images, or in this case we only serve JSON.
 
  I'm wondering what are the recommended configurations for
  the Apache web-server in these situations?  Should we disable
  keep-avlie?  What about other directives?  Apache is our
  bottleneck, and we're trying to optimize it. Should we use nginx instead?
 
  Please let me know your suggestions.
 
  Thank you,
  -behzad

 How much of that data is cachable? You're likely to get bigger performance
 gains from caching frequent data.

 Keep-alive at maybe 1 second.

 But would need to know more about the app to be able to suggest more

 Bastien


Re: [PHP] Apache to serve RESTful requests using PHP

2013-02-09 Thread AmirBehzad Eslami
Stuart, thanks for your detailed response.

  I find it unlikely that Apache is your bottleneck,
 especially with a service involving MySQL.
 How have you come to this conclusion?

Apache is the entry-point to our service, and I did a
benchmark with AB to see how it can handle concurrent
requests in a timely fashion.  After a number of 50 concurrent
requests, the average time per request reached from less than
a second to 5 seconds.

On the other hand, the MySQL's slow_query_log was clear,
with long_query_time = 1.

Our MySQL database consists of less than 200 records,
distributed in normalized tables, yes, queries are making joins,
but the overall performance is OK.

 As far as keep-alive goes, how frequently will individual
 clients be accessing the service?

There are only a few clients that call the service.  These clients
are PHP-driven web pages. Each page has its own unique ClickID
and a set of other unique parameters per user visit.  These pages send
these parameters to the service using php-curl, and expect a generated
response to be returned.  That's why I'm saying each request and
response is unique.

Whenever a user visits a web-page, there would be a call to the
web-service.  At the moment, we don't know number of concurrent
visits.  We're looking for a way to figure that out in Apache.

Is there a way to see if the requests are using the previously keep-alived
http channel?  Because same client will send requests to the service,
and I'm curious to know if the Apache will allocate the already-opened
channel, or will create a new one?

 If you are using joins to pull in extra data (i.e. IDs to a name
 or similar) look at using Memcache for those, but make sure
 that when they're updated in the DB they're also updated in Memcache.

Memcache or Redis, I'm going to add a caching layer between
MySQL and PHP, to store the de-normilized data.

I'm starting to learn more about nginx + php-fpm, thanks for
sharing your positive experience about this.

-behzad


Re: [PHP] Joining a team, where no wiki or docs are available

2012-09-25 Thread AmirBehzad Eslami
Wow. David. That was a great help with every detail !
Thanks for sharing that with us.

One side question:
Without OOP, how do you handle Unit Tests?
Do you know a Testing framework for procedural code?


[PHP] Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
Hi,

i'm going to join a mid-size company with a few PHP-driven projects
written in procedural PHP, million years old.

At the moment, they don't have a wiki or any documentation about their
projects. For me, the first challenge in probation period is to understand
how their code works.
*
Considering that there is no wiki or docs, How can I see the Big Picture?*
i'm sure this is a common problem for programmers everywhere.

What approach do you use in a similar situation?
Is there a systematic approach for this?
Is there reverse-engineering technique to understand the design of code?

Please share your experience and thoughts.

-Thanks in advance,
Behzad


Re: [PHP] Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
Thanks Samuel.

Actually I'm not going to add features or fix bugs, they're trying a
refactoring process, to improve the design of code. So, I really need
to understand the current design at the outset.

On Mon, Sep 24, 2012 at 5:41 PM, Samuel Lopes Grigolato 
samuel.grigol...@gmail.com wrote:

 I would recommend reading this article:
 http://www.infoq.com/articles/tips-to-developers-starting-on-large-apps

 It's targeted to Java developers, but the concepts are valid to any
 language.

 Hope it helps.

 Cheers,
 Samuel.



Re: [PHP] Re: Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
Jim wrote:

 If you really are joining a team, I would expect that the teammates
would
 be guiding you through their systems.

True, but based on my experience, most programmers are not good when it
comes
to explain stuff. So, I should rely on my own.


Re: [PHP] Re: Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
That's like erasing the question from the paper, in order to give it a
solution!

I was thinking about this problem for a while, and I've ended-up with this
approach:

#1 Start using the software as an End-User (don't care about the code) to
understand the business-value of the software
#2 Take a look at the database scheme, try to understand the entities and
their relations
#3 As you use the software, you'll become more curious about its features
and how they've implemented.
#4 Start to see how they've implemented common problems, such as:
Authentication, CRUD, etc. How the other interesting features are
implemented

So that's an approach. What do you think?

You can't join a team and ask them: How this software is implemented?
They'll simply stare at you. Instead, *we need to ask smart questions*.
Now where these smart questions come from?
We need to understand some of the design prior to ask questions, right?
With that basic understanding, we can ask good questions, and will gain
benefit
from the answers.

On Mon, Sep 24, 2012 at 5:52 PM, Mihamina Rakotomandimby miham...@rktmb.org
 wrote:

 On 09/24/2012 05:19 PM, AmirBehzad Eslami wrote:

 True, but based on my experience, most programmers are not good when it
 comes
 to explain stuff. So, I should rely on my own.


 Choose another team?

 --
 RMA.


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




-- 
Kind regards,
-behzad


Re: [PHP] Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
+Like.
The idea of mapping the db-structure and logic behind each page is
interesting.
Thanks for sharing.

On Mon, Sep 24, 2012 at 6:06 PM, admin ad...@buskirkgraphics.com wrote:



 I would start by mapping their databases structure.
 Now for each page I would map out any functions, statements or includes to
 a diagram and documenting explanations for everything.

 This will allow you to see pitfalls, bad coding, and areas of improvement.
 This will also allow you do explain to them what the application really
 does.
 Think documentum









-- 
Kind regards,
-behzad


Re: [PHP] Re: Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
Never worked with Emacs or genben. I'm a fan of vim ;)
But thanks a ton, based on your suggestion, I just found vim-dbgp

On Mon, Sep 24, 2012 at 6:27 PM, Mihamina Rakotomandimby miham...@rktmb.org
 wrote:


 #5 install xdebug + geben + emacs and have a look at the call stacks and
 bottlenecks.


 --
 RMA.

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




-- 
Kind regards,
-behzad


Re: [PHP] Joining a team, where no wiki or docs are available

2012-09-24 Thread AmirBehzad Eslami
Shiplu,
For debugging, what else do you use beyond xdebug and var_dump() ?

On Mon, Sep 24, 2012 at 6:07 PM, shiplu shiplu@gmail.com wrote:

 If there is no wiki there could be inline comment. If not inline comments
 and those are written by your peers, dont join that team.
 Even there are inline comments you'll need to understand the architecture
 fast. Inline comments will help to understand a small context but not the
 whole
 For this try run the application with a debugger. And step through it.  If
 you know debugging well in PHP you'll understand the workflow.

 --
 Shiplu.Mokadd.im
 ImgSign.com | A dynamic signature machine
 Innovation distinguishes between follower and leader




[PHP] Log Rotation, leave it to OS or do it in PHP code?

2011-02-26 Thread AmirBehzad Eslami
Dear list,

It seems that Python has already a Log Rotation mechanism,
which solves the problem of log file growth.

I'm wondering whether there is any PHP-based solution around?
Now let me ask from a different view:

Is it a good approach to implement the Rotation mechanism to PHP? (Code Level)
Or leave the job to the operating system and other utilities?

Where is the right place to implmenet the Rotation? In Code? In OS?
PHP? or a Bash Script?

Thanks,

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



Re: [PHP] Counting Online users, but not using a Session Table in MySQL

2011-01-28 Thread AmirBehzad Eslami
Jim, I'm already using the solution you mentioned.

The problem is about the performance.
One solution is to increase the performance by using Memcached.

But counting online users always requires a __new__fresh__ COUNT(*) query, even
under Memcahched. Since the COUNT(*) result is very dynamic and could
change every second, it should not be cached.

I'm looking for a faster way to count online users.
COUNT(*) is time consuming under MySQL.

Any light-weight solutions?

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



[PHP] Centralizled Authentication

2010-12-02 Thread AmirBehzad Eslami
Dear list,

We have dozen of applications, mostly written in PHP and Python.
They're distributed on different servers, but i'm trying to integrate them
somehow.

Each application has its own users.
Is there a way to store all username/passwords into a single datasource
and give each user, her proper permissions?

Since i'm just a php-programmer, i *thought* of a MySQL database to
hold these data, and then use a SOAP-Server to handle the authentication
across those applications.

Once a user provides her username/password, a SOAP Request will be
made to a PHP-Driven Authentication Server, which handles the job to
check the permissions and user's identity.

It sounds slow, isn't it? Is there a better solution?
How do you make authentication across a network of applications?

-- 
Kind regards,
-behzad


Re: [PHP] Centralizled Authentication

2010-12-02 Thread AmirBehzad Eslami
Suppose you're running phpBB with another php-driven application.
phpBB has a user table where the username/password/email/.. of each user
is stored at mysql. Once a user logs-in to the website, the Last Login
timestamp updates
on the users table at mysql.

How do I use LDAP in this type of application?

1) Move entire records of Users and their attributes (e.g.
last_login_time) to LDAP server?
In this mehtod, after each successfull login request, I also need to update
the related record on LDAP.

2)  Should I use LDAP to store only the username and passwords?
In this method, I need to update the record on MySQL database, but I should
keep the MySQL
and LDAP syncronized, since a user may want to change her password.

What do you think guys? Please let me know.


[PHP] PHP-driven alternative to Crystal Report

2010-11-26 Thread AmirBehzad Eslami
Dear List,

I'm looking for an open-source database reporting tool, which is written in
PHP.
Do you know of any php-driven alternative to Crystal Report?
What do you recommend?

Please let me know.
Thank you very much.

-behzad


[PHP] Implementation of non-linear business processes in PHP

2010-01-17 Thread AmirBehzad Eslami
Dear List,
Helllo!!!

I'm trying to write a web application for my own ISP, to simplify the
processing of orders for Internet Accounts,
creating reports of their users, and keeping track of their sales.

A brief history:
This ISP provides ADSL connections over ordinary telephone lines for home
users. The activation of ADSL for these kind of users
is a bit complicated, and its business process is not linear. For example,
some telephone lines do not support separation of
data and voice, because their type is PCM. There are many situations that
they can't provide ADSL.
The ISP company has many resellers on the country, there are many
Administration Groups, etc.

With PHP, I'm trying to simplify this process. I guess there are many
examples out there, but I want to write
the application by myself in PHP.

A short list of requirements are:

1) Ability to add/edit Resellers, which in turn, they can have their own
Admins, Standard Users (ISP Insiders), and
they have different roles. Perhaps one user is allowed to view quotes, the
other is allowed to edit invoices,
and one user is allowed to finalize the orders.
2) Ability to change the order of different processes. For example, in one
situation the payment should occur before
the ADSL connection, in the other scenario the payment is not necessary at
the first place ( a 30-day trial connection ).

Is there any solution to implement non-linear business processes in PHP
(where different tasks could be done by different users,
with different roles, in different order)?

Please let me know what you think.
I appreciate your kindness. Thank you.
-b


[PHP] PHP-based Workflow Editor

2010-01-17 Thread AmirBehzad Eslami
Dear list,

Java has a lot of tools to implement Workflows, but I'm trying to find a way
to achieve the same results in PHP. It seems that ezComponents has a
Workflow mechanism,
but it lacks the editor.

Is there any PHP-based Workflow Editor?
Do you have any recommendation?

Thank you in advance,
-b


[PHP] A PHP-driven script to determine if the environment is configured correctly (checklist)

2009-12-16 Thread AmirBehzad Eslami
Dear list,
e-Greetings,

I've developed some PHP-driven web applications. These applications will be
installed on different
linux-based servers (typically Debian and Redhat). Usually, after I copy the
files to the
server, they DO NOT WORK, so I spend hours to debug the problem. Problems
are very funny,
for example, the program is giving strange errors, and it is not working
because short_open_tags are off !

I decided to write a PHP script to check if server's configuration meets my
requirements.
- checking whether some php extensions are loaded, eg. MCrypt.
- checking wheather short_open_tags is ON
- checking whether mod_rewrite is enabled
- etc.

Here's my question:

- How do you check if .htaccess is working, *** via php code *** ?
It's easy to check if .htaccess exists (@php: file_exists), but how to make
sure if .htaccess is working?!
- How do you check if AllowOverride is set to All in apache's configuration?

Please let me know what do you think. Thank you in advance.
-behzad


Re: [PHP] Server-side encryption to prevent form hacking: new idea?

2009-12-12 Thread AmirBehzad Eslami
Suppose you have the following array:
*
?php

$cities = array(Tehran, Isfahan, Tabriz);

?*

which is used to generate the following Select:

*select name=city
   option value=TehranTehran/option
   option value=IsfahanIsfahan/option
   option value=TabrizTabriz/option
/select*

You can check whether the submitted value is valid or not, using the
following code:

*if ($_SERVER['REQUEST_METHOD'] == POST) {

   if (!in_array($_POST['city'], $cities) die('Invalid');

}
*
Hope this helps.


On Sat, Dec 12, 2009 at 12:18 AM, Andrew Ballard aball...@gmail.com wrote:

 On Fri, Dec 11, 2009 at 3:34 PM, Michael Shadle mike...@gmail.com wrote:
  On Fri, Dec 11, 2009 at 12:29 PM, Mattias Thorslund
  matt...@thorslund.us wrote:
  Kelly Jones wrote:
 
  If you have an HTML form select field xyz with possible values
  apple, banana, and cucumber, anyone can easily set xyz to an
  arbitrary value.
 
  To prevent this, I create a hidden field code[xyz] with value:
  base64_encode(mcrypt_ecb(
   MCRYPT_RIJNDAEL_256,$salt,apple,banana,cucumber,MCRYPT_ENCRYPT));
 
  where $salt is stored in a file outside my webroot.
 
  The script receiving the POST data uses:
 
  mcrypt_ecb(MCRYPT_RIJNDAEL_256,$salt,
   base64_decode($_REQUEST[code][xyz]), MCRYPT_DECRYPT);
 
  and confirms xyz is really one of apple, banana, or cucumber.

 [snip]

 
  If the server-side script knows which values are expected, then there is
 no
  need to send that to the client (browser) and back. If this is not
 simply
  hard-coded in your script, you can keep it in a different file, in a
  database, or in the session, depending on your particular situation. For
  most of the fields, the number of acceptable values aren't limited to a
  small set, so it's more practical to check for expected length, data
 type,
  and escape the data before saving it.
 
  Cheers,
 
  Mattias
  you don't necessarily need encryption, you could use digests instead
  and issue a use-once ticket as well.
 

 Why is any of this necessary? Most of the time I build select lists
 from arrays, so it is easy to test the value submitted by the client
 to make sure it exists in the array without any encryption or hashing.
 Am I missing something?

 Andrew

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




-- 
Kind regards,
-behzad


[PHP] FCKEditor, TinyMCE, ... I need a light weight WYSIWYG HTML Editor

2008-08-17 Thread AmirBehzad Eslami
Dear list,

I'm looking for a light weight WYSIWYG HTML Editor to allow
users to send private messages to each other in a forum application.

FCKEditor is too complex and very huge for my purposes. I want a
simple editor. What do you recommend?

Thanks in advance
-- 
Kind regards,
-behzad

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



Re: [PHP] Doctrine vs. Propel

2008-02-06 Thread AmirBehzad Eslami
Thank you all for your kind replies.


[PHP] Doctrine vs. Propel

2008-02-04 Thread AmirBehzad Eslami
Dear List,

I've just heard of ORM (Object Relational Mapping) frameworks written for
PHP.
It seems that there are two major frameworks here: Doctrine and Propel:

http://www.phpdoctrine.org/
http://propel.phpdb.org/trac/

I wonder which one is better? What is the difference between these?
I'm talking about the learning curve, peroformance.
What are the advantages/disadvantages of each one?

Thank you in advance,
Behzad


[PHP] is_prefix() - checking wheather $A is prefix for $B

2007-12-29 Thread AmirBehzad Eslami
I want to write a function to check
whether string $A is a prefix for string $B or not.

I writing this function in order to prevent directory traversal
during a download request. (e.g., download.php?file=..\index.php)

I want to make sure that the realpath() of the requested file is
within the realpath() of the download-directory. Trying to make
sure that the the $download_dir is a prefix for $filepath.

@see: http://en.wikipedia.org/wiki/Directory_traversal
**
*TWO FUNCTIONS:*

function is_prefix1($prefix, $str) {
return (0 == strncasecmp($prefix, $str, strlen($prefix)));
}

function is_prefix2($prefix, $str) {
return (0 === stripos($str, $prefix));
}
*USAGE:*
if (is_prefix1('a', 'abcdef'))
 echo 'prefix1 returned True!', 'br /';

if (is_prefix2('a', 'abcdef'))
 echo 'prefix2 returned True!', 'br /';


Do these functions do the same job?
Which one provides better performance?

-behzad


Re: [PHP] is_prefix() - checking wheather $A is prefix for $B

2007-12-29 Thread AmirBehzad Eslami
In case you haven't realized it, I have already written two functions to
check
for a prefix !! The question is: Which function is better? (is_prefix1() or
is_prefix2())

On 12/29/07, Zoltán Németh [EMAIL PROTECTED] wrote:

 2007. 12. 29, szombat keltezéssel 13.39-kor AmirBehzad Eslami ezt írta:
  I want to write a function to check
  whether string $A is a prefix for string $B or not.

 if (strpos($B, $A) === 0) {
 echo '$B begins with $A';
 } else {
 echo '$B does not begin with $A';
 }

 greets
 Zoltán Németh

 
  I writing this function in order to prevent directory traversal
  during a download request. (e.g., download.php?file=..\index.php)
 
  I want to make sure that the realpath() of the requested file is
  within the realpath() of the download-directory. Trying to make
  sure that the the $download_dir is a prefix for $filepath.
 
  @see: http://en.wikipedia.org/wiki/Directory_traversal
  **
  *TWO FUNCTIONS:*
 
  function is_prefix1($prefix, $str) {
  return (0 == strncasecmp($prefix, $str, strlen($prefix)));
  }
 
  function is_prefix2($prefix, $str) {
  return (0 === stripos($str, $prefix));
  }
  *USAGE:*
  if (is_prefix1('a', 'abcdef'))
   echo 'prefix1 returned True!', 'br /';
 
  if (is_prefix2('a', 'abcdef'))
   echo 'prefix2 returned True!', 'br /';
 
  
  Do these functions do the same job?
  Which one provides better performance?
 
  -behzad




[PHP] Generating Random Numbers with Normal Distribution

2007-12-10 Thread AmirBehzad Eslami
Dear list,

For some computer-based simulation, i need to
generate random numbers that have a normal distribution.

It seems that PHP's rand() and mt_rand() functions return
uniformly distributed numbers which is not suitable for
simulation purposes.

Is there any way to generate random numbers with
normal distribution in PHP?

Thanks in advance
-abe

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



[PHP] The PHP License

2007-11-28 Thread AmirBehzad Eslami
Hi list,

Below statement is borrowed from PHP License here[1]:

 The name PHP must not be used to endorse or promote products
 derived from this software without prior written permission. For
 written permission, please contact [EMAIL PROTECTED]


Does this mean that saying this website is Powered by PHP is illegal
without a written permission?


P.S.
1. http://www.opensource.org/licenses/php.php


Re: [PHP] The PHP License [SOLVED]

2007-11-28 Thread AmirBehzad Eslami
Thanks Jochem and Daneil. I got it.


Re: [PHP] Should I put pictures into a database?

2007-11-28 Thread AmirBehzad Eslami
On Wednesday 21 November 2007 03:14:43 Ronald Wiplinger wrote:
 I have an application, where I use pictures. The size of the picture is
 about 90kB and to speed up the preview, I made a thumbnail of each
 picture which is about 2.5 to 5kB.
 I use now a directory structure of   ../$a/$b/$c/pictures

I rather to store images on the file-system, since database is another
level over the file-system. However, I still need to store a pointer for
every image into the database. This leads to storing the file names
twice: one time in file-system, and one time in db.
Isn't this redundancy?

Sometimes we can avoid this, especially if we have an image per
record (e.g., Users' Avatars).

Suppose you allow each user to upload a GIF/PNG/JPEG image;
the below code assigns the correct image for every user:

foreach ($users as $user) {
$user['avatar'] = reset(glob('../img/avatars/' . $user['id'] .
'.*'));
}

If you can grant the images are .GIF, then you can reduce the
overhead of searching for images:

foreach ($users as $user) {
$user['avatar'] = '../img/avatars/' . $user['id'] . '.gif';
}

Regards,
Behzad


[PHP] Concatenation vs. Interpolation

2007-08-11 Thread AmirBehzad Eslami
Hi,

FASTER CODE!

This question involves Coding Style, Readability, Write-ability and
Performance.
Some people use the . operator to concat an string to a variable, some
people use interpolation (embeding variable into string).

=
1st Method (Concatenation)
$str = 'My name is ' . $name;

2nd Method (Interpolation)
$str = My name is $name;
=

I know that the 1st Method is much faster, according to
some benchmarks, which one of them is available
in the book Advanced PHP Programming, page 470.

Could we consider the 1st Method as a Best Practice, which offers
better Performance?

I know that the performance here is not very much, but is it
considerable in a high-traffic website?

Thank you in advanced for sharing your opinions,
Behzad


Re: [PHP] Concatenation vs. Interpolation

2007-08-11 Thread AmirBehzad Eslami
You're right. There is a low benefit in performance. But I think it's
valuable
in high-traffic websites. Of course, we should consider a lot of thing to
have a better performance, but Concatenation, IMO, is the best practice.
Let me explain:

َActually, the programmers' preference on readability and write-ability
varies.
I think that concatenation provides a more readable syntax, since it
allows us to distinguish variables from plain strings very easily.
Consider the following code:

$str = 'My name is ' . $name . ' and I live in ' . $city;
VS.
$str = My name is $name and I live in $city;

(You may view the above code in an Editor with syntax-highlighting
capability for a better result). However, it is possible to offer
opposite examples.

In addition to the Performance on Speed, Concatenation uses less memory
than Interpolation, as explained in PHP Manual. Take a look at the
following URL:

http://us2.php.net/manual/en/language.types.string.php

Quote:
Note:  Parsing variables within strings uses more memory than string
concatenation. When writing a PHP script in which memory usage is a concern,
consider using the concatenation operator (.) rather than variable parsing

Thus, I think that it is better to use Concatenation instead of
Interpolation.
Since it provides Performance, both on Speed and Memory Usage.

There is a benchmark available here:
http://us2.php.net/manual/en/function.print.php#66392


On 8/11/07, Tijnema [EMAIL PROTECTED] wrote:

 On 8/11/07, AmirBehzad Eslami [EMAIL PROTECTED] wrote:
  Hi,
 
  FASTER CODE!
 
  This question involves Coding Style, Readability, Write-ability and
  Performance.
  Some people use the . operator to concat an string to a variable, some
  people use interpolation (embeding variable into string).
 
  =
  1st Method (Concatenation)
  $str = 'My name is ' . $name;
 
  2nd Method (Interpolation)
  $str = My name is $name;
  =
 
  I know that the 1st Method is much faster, according to
  some benchmarks, which one of them is available
  in the book Advanced PHP Programming, page 470.
 
  Could we consider the 1st Method as a Best Practice, which offers
  better Performance?
 
  I know that the performance here is not very much, but is it
  considerable in a high-traffic website?
 
  Thank you in advanced for sharing your opinions,
  Behzad
 

 Code readability is quite important when working with a team on a
 project, and if you got for method 1 on things like this:
 $str = 'a href='.$url.'';
 It gets quite inreadable, having a double qoute next to a single quote.
 while this looks much better:
 $str = a href='$url';

 I just did some benchmarks myself, and you can see that concatenation
 is definitly a little bit fast, but it's only 2 seconds on 10 million
 loops:
 For 10,000,000 loops:
 Concatenation single quote:5.62786102295
 Concatenation double quote:5.6335657
 Interpolation:7.32201290131

 Test code used:
 ?php

 $x = 0;
 $str = '';
 $add = '?';

 $time[1] = microtime(TRUE);
 for($x = 0; $x  1000; $x++) {
 $str = 'a href='.$add.'';
 }
 $time[2] = microtime(TRUE);

 $x = 0;
 $str = '';
 $add = '?';

 $time[3] = microtime(TRUE);
 for($x = 0; $x  1000; $x++) {
 $str = a href='.$add.';
 }
 $time[4] = microtime(TRUE);

 $x = 0;
 $str = '';
 $add = 'def';

 $time[5] = microtime(TRUE);
 for($x = 0; $x  1000; $x++) {
 $str = a href='$add';
 }
 $time[6] = microtime(TRUE);

 echo 'For 10,000,000 loops:';
 echo 'br /Concatenation single quote:'.($time[2]-$time[1]);
 echo 'br /Concatenation double quote:'.($time[4]-$time[3]);
 echo 'br /Interpolation:'.($time[6]-$time[5]);

 ?

 Tijnema

 --
 Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info



Re: [PHP] Symfony versus CakePHP?

2007-07-21 Thread AmirBehzad Eslami

What is difference between Zend Framwork and other frameworks like
CakePHP? I'm trying to develop a sample blog for educational
purposes in Zend Framwork, but some times I feel that I'm learning
a new language or a new programming paradigm.

On 7/21/07, Larry Garfield [EMAIL PROTECTED] wrote:


Back in January I was looking for a framework for a project that ended up
being canceled anyway. :-)  I considered both CakePHP and Symfony, and had
decided on CakePHP for a very simple reason: It was smaller.  It was pure
PHP
while Symfony relied on Propel which in turn used YAML syntax to define
its
object model, which it then compiled to XML, which in turn was used to
generate both the SQL tables and the base classes in PHP.

I saw no reason to learn Yet Another Markup Language (I can't take
seriously
any markup system that acknowledges that it serves no useful purpose) and
install/load/use a multi-meg system when Cake was far smaller, built its
classes off of the SQL directly, and didn't require me to learn still more
obscure syntax.

Of course, I hate Rails-style code-generation frameworks anyway, so I'm
kinda
glad I never actually built that project. :-)  YMMV.

On Friday 20 July 2007, Steve Finkelstein wrote:
 All,

 I'm terribly sorry if this is a redundant inquiry. I'm a rather
 inexperienced developer who's catching on quickly, and looking for a
 framework to build out a project I've been assigned. I'm more of a read
 a book and try things out type of learner.

 My question to those with more experience, what exactly is the
 difference between CakePHP and Symfony? I'm looking into both of them
 for a potential framework to make robust and scalable code. They both
 seem to try to obtain the same goals with their project, however Symfony
 has text written about it, etc.

 Anyway, thank you for any insight.

 - sf


--
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]  ICQ: 6817012

If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the
possession
of every one, and the receiver cannot dispossess himself of it.  --
Thomas
Jefferson

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




Re: [PHP] Pirate PHP books online?

2007-07-21 Thread AmirBehzad Eslami

I'm living in a country where people do not afford to buy real books.
Most people earn $250~$400 per month. $50 for a book is too damn
expensive. In addition, since US has restricted business with us,
no body ships books to us. And we don't have Credit Card, since
Master Card, Visa, Paypal do not offer services to us.

How can we read books in such a country?
I would like to know your opinions. Thank you.


On 7/22/07, Chris Shiflett [EMAIL PROTECTED] wrote:


David Powers wrote:
 I suspect that your estimate of the advances paid by Apress/friends of
 Ed is inflated. Royalties are no secret: Apress publishes its standard
 contract on the web for prospective authors to see. The basic rate is
 10% of the net income received by the publisher. Since heavy discounting
 is prevalent in the publishing industry, this means the author ends up
 with less than 5% of the book's cover price. So on a book with a cover
 price of $40, the author gets less than $2.

Based on the fact that this is almost identical to every other publisher
(O'Reilly, Sams, etc.), and based on the fact that Richard said he has a
lot of experience in this industry, I suspect his estimate was spot on.

You're right, though, it's difficult to get any return on your time
investment. :-)

Chris

--
Chris Shiflett
http://shiflett.org/

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




[PHP] Migration from MySQL to MS-SQL Server

2005-12-09 Thread AmirBehzad Eslami
Hi List,

I want to re-implement a PHP-driven package named ATutor (http://atutor.ca)
to work with MS-SQL Server.
Currently, it works with MySQL.

Unfortunately, authors of ATutor have not defined a class for database
connectivity.
In other words, they call each mysql functions directly in their code.
It seems that I must change every line of code to make ATutor work with
MS-SQL Server.

1) Is it suffice to replace every mysql_FUNCTION  with mssql__FUNCTION
in the code? I realized that most of MSSQL functions are very similar to
MySQL functions, but their prefixes are different.
(I should kindly thank the PHP Development Team for this)

2) I have not worked with MS-SQL Server before. Is there anything else which
I should keep in mind?

Thank you in advance,
Behzad


Re: [PHP] Lowest PHP version to work with MySQL 4.1.x

2005-12-01 Thread AmirBehzad Eslami
Brent and Oliver,
Thank you for your assistance.

I found some notable solutions from MySQL Forums:

http://forums.mysql.com/read.php?11,6400,6400#msg-6400

Regards,
Behzad


[PHP] Lowest PHP version to work with MySQL 4.1.x

2005-11-30 Thread AmirBehzad Eslami
Hi List,

I have noted that some versions of PHP are unable to work with MySQL 4.1.x.

1) Should I upgrade to PHP 5?
2) What is the lowest PHP version which works fine with MySQL 4.1.x?

Regards,
Behzad

P.S.
I don't use Improved MySQL extension in PHP.
I just need MySQL 4.1.x for multi-byte character support.


[PHP] phpInfo() executed on Yahoo!

2005-06-20 Thread AmirBehzad Eslami
Yes! phpInfo() on Yahoo!

URL: http://advr1.advertising.scd.yahoo.com/

1) First I was at: http://promo.yahoo.com/user_research/
2) I moved to the upper directory: http://promo.yahoo.com/
3) Do you Yahoo!, the new page said. So I did View Source.
4) http://advr1.advertising.scd.yahoo.com/

Cheers,
Behzad

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



[PHP] phpInfo() executed on Yahoo!

2005-06-20 Thread AmirBehzad Eslami
Yes! phpInfo() on Yahoo!

URL: http://advr1.advertising.scd.yahoo.com/

1) First I was at: http://promo.yahoo.com/user_research/
2) Then I moved to an upper directory: http://promo.yahoo.com/
3) Do you Yahoo!, the new page said. So I did View Source.
4) http://advr1.advertising.scd.yahoo.com/

Cheers,
Behzad

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



[PHP] phpinfo(); executed on Yahoo!

2005-06-20 Thread AmirBehzad Eslami
Yes! phpInfo() on Yahoo!

URL: http://advr1.advertising.scd.yahoo.com/

1) First I was at: http://promo.yahoo.com/user_research/
2) Then I moved to an upper directory: http://promo.yahoo.com/
3) Do you Yahoo!, the new page said. So I did View Source.
4) http://advr1.advertising.scd.yahoo.com/

Cheers,
Behzad

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



Re: [PHP] phpInfo() executed on Yahoo!

2005-06-20 Thread AmirBehzad Eslami
On Monday, June 20, 2005, Jason Barnett wrote:

JB [..] but it would have been cool to see what things
they've done to handle the number of page requests they have.


Take a look at the attached file.


HTH,
Behzad

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