Jaslabs: High performance Software

High Performance Software

Archive for the 'tips' Category

How to write PHP extensions

By Justin Silverton

What is a php extension?

A PHP extension is a way to write extensions for the php language that would otherwise not be practical in the php language itself.  The main benefit is speed of execution.  An extension can be created in a compiled language such as c/c++ (if you look in your php.ini file, you can see examples of many extensions you most likely have already used) and loaded through a .dll (in windows) or a .so (in *nix) environment.

Types of extensions

Zend extensions

  • pros: very fast and built into the core zend engine, which is what php runs on.  This type of extension would be an actual change to the php interpreter/language (objects, expressions, etc).
  • cons: if written improperly, can cause instability.  These extensions are not recommended in most situations.

External extensions

  • pros: Loaded at run-time (only the extension needs to be re-compiled when you make a change).  Functionality is available to the script that loads it and memory is freed when the script ends.
  • cons: Loading and unloading of extension may take up more processing power depending on how often the script loading it is accessed.

Built-in extensions

  • pros: compiled with php and loaded with the php processes.
  • cons: any changes to the extension require a complete re-compilation of php.

Example Code

An example extension project can be downloaded here

This example is for the *nix platform.

How to build:

$ phpize
$ ./configure –enable-hello
$ make

After running the above commands, you should have a hello.so file in ext/hello/modules/ . Now, you can copy this to your extensions directory (/usr/local/lib/php/extensions/ is the default, check your php.ini to be sure) and add the line extension=hello.so to your php.ini to trigger it to load on startup.

More in-depth information can be found here

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
No comments

Storing passwords in php 5

By Justin Silverton

This topic is something that every php programmer will have to deal with at some point in their programming career. You have just created a system where a user needs to login with some type of username/password combo and you need to store the password (either in plaintext or in some type of database). How do you safely go about doing this? You could store it in plaintext, but this would be a bad idea. Anyone that has access to your server would also be able to get your passwords and the data that they are trying to protect.

A simple yet effective approach

In the past, sha1() or md5() would have been the most effective and secure way to encrypt your data, but recently it has been shown that these functions can be compromised and there is another set of more secure functions.

The function name is called hash(). Here is a list of it’s functionality/parameters:

string hash ( string algo, string data [, bool raw_output] )

Parameters

Algo: Name of selected hashing algorithm (i.e. “md5″, “sha256″, “haval160,4″, etc..)

Data: Message to be hashed.

Raw_Output: When set to TRUE, outputs raw binary data. Default value (FALSE) outputs lowercase hexits.

Returns: Returns a string containing the calculated message digest as lowercase hexits unless raw_output is set to true in which case the raw binary representation of the message digest is returned.

Using this function (note: this function is only available in php 5.1.2 and above)

You can use the following funcion: hash_algos() to get a list of system specific hashing algorithims that are supported by php.

(Inserting into your database/storing)

$password = hash(’sha256′,$_POST[’password’);

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
4 comments

Five Tips for Freelance PHP Coders

Introduction

If you’ve decided that working for yourself as a self-employed web developer or PHP coder sounds like your cup of tea, but you feel as if the task is a bit daunting, then listen up. We’ve put together a list of helpful tips that will enable you to go wherever it is you want your own business to go. You should know that these are in no particular order and we consider them all equally important. As well, please be advised that this is by no means a guarantee to your success, nor is it a comprehensive list of potential obstacles you may encounter.

1. Guard Your Reputation With Your Life

Your reputation is the most important asset you have, and you should treat it as such. You might be the most competent coder on the planet, but if you have a reputation for being difficult to work with, or unreliable, getting new clients will be more difficult, you will lose referrals from current clients and you will find you will have to prove yourself over and over again. Don’t make promises you can’t keep, and remember that your actions today may have a profound effect on the future success of your business. Maintaining a contract business is difficult enough without you inadvertently sabotaging your own efforts.

2. Be Passionate About Your Work

Clients want to see genuine enthusiasm and they will take comfort in the fact that you have a personal investment in their web site. A larger company may be able to offer the same coding services that you can, but you can use that “personal touch” to your advantage.

3. Be Responsive And Communicate Often

Even if things are crazy or if you are extremely behind schedule, taking five minutes to make a quick change for a client’s site or sending a quick e-mail to update your client about the status of his project will really go a long way in diffusing a potentially damaging situation. Of course, this will only buy you a little time, but it is much better than ignoring a client altogether and aggravating the situation.You can also provide status reports for your clients weekly or bi-weekly, so they are kept in the loop as to how things are progressing. Knowing that you will have to be presenting these reports helps you maintain accountability for the project and keep you moving forward, as well as keeping your client informed.Along with this goes the advice of promptly returning phone calls and e-mails. Some of us are averse to using the phone, but by giving your client the courtesy of returning a phone call, you are in essence communicating that you value their business and that you are there to help. Likewise with e-mails, they should be responded to immediately, not three or four days later.

4. Don’t Be An Ostrich

When things get overwhelming (and they will), resist the urge to stick your head in the sand and play another game of . This will only exacerbate the situation. If you cannot see the light at the end of the tunnel, get help. Enlist a trusted colleague with a few small pieces of the bigger project. Better yet, enlist several trusted colleagues. Whatever you do, make sure you’re doing something to chip away at the workload.

5. Remember That You Are Your Own Ambassador

Tact and diplomacy can be your best friends, especially when a client is asking for the impossible. Unlike coding jobs in the industry, where you have a full staff of sales and marketing and executive types buffering the client from the dungeons of the coders, when you are your own boss, you are thrust onto the surface world and must deal directly with the clients. Try not to be condescending or openly laugh at their ignorance; you will only alienate them and risk losing them as a client (and any referrals they might have passed your way). At least wait until they are no longer within earshot; then mock away.

Original article:

http://www.php-mag.net/magphpde/magphpde_article/psecom,id,746,nodeid,21.html

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
5 comments

How to backup and restore outlook express 6.0

This works with outlook express 6.0 on any platform (I have used it on windows XP,2003, and 98).

Backing up your email

Open Outlook Express

A) Backup accounts

1) goto tools->accounts
2) click on the mail tab
3) any account that is there, click on “export” and save these files to your harddrive

B) Backup emails

1) find your store folder by going to tools->options->maintenance and clicking on “store folder”
2) backup this entire folder to a separate location

Any message rule will need to be backed up by hand.

Restoring your email

Open Outlook Express on the target computer

A) restoring accounts

1) goto tools->accounts
2) click on the mail tab
3) click on “import” and import each file that you expored from the above steps.

B) Restore folders

1) look at the backup folder from above, and create new folders with the same name as any dbx file that is there (IE: if there is a file called my_email.dbx, make a folder called my_email)

C) Restore all email

1) get the store folder using part b step 1 from above
2) close outlook express
3) copy all backup data to your new store folder from part 1
4) open outlook express and it should be an exact copy of the mailbox that was backed up.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
No comments

using paypal mass payment

By Justin Silverton

IntroductionMass Payment allows anyone with a Premier or Business account to send multiple payments instantly—saving time, money and the hassle of having to individually send funds to every payment recipient. Mass Payment allows anyone with a Premier or Business account to send multiple payments instantly—saving time, money and the hassle of having to individually send funds to every payment recipient.Click the links on the left of this page to learn more about Mass Payment.

Mass Payment allows anyone with a Premier or Business account to send multiple payments instantly—saving time, money and the hassle of having to individually send funds to every payment recipient.Click the links on the left of this page to learn more about Mass Payment.Mass Payment can be used for such things as:

Mass Payment allows anyone with a Premier or Business account to send multiple payments instantly—saving time, money and the hassle of having to individually send funds to every payment recipient.Click the links on the left of this page to learn more about Mass Payment.Mass Payment can be used for such things as:

  • Affiliate commissions
  • Customer rebates
  • Pay-to-surf rewards
  • Employee benefits
  • Lottery prizes
  • Survey incentives

File FormatYou must create a tab-delimited file containing your recipients’ information to send a Mass Payment file. A tab-delimited file can be generated from most spreadsheet applications, such as Excel.You must create a tab-delimited file containing your recipients’ information to send a Mass Payment file. A tab-delimited file can be generated from most spreadsheet applications, such as Excel.Column 1: recipients’ email addresses.
Column 2: the payment amounts for each recipient.
Column 3: the three-letter currency code for the currency of the payment (only one currency type is allowed for each Mass Payment file):
You must create a tab-delimited file containing your recipients’ information to send a Mass Payment file. A tab-delimited file can be generated from most spreadsheet applications, such as Excel.Column 1: recipients’ email addresses.Column 2: the payment amounts for each recipient.Column 3: the three-letter currency code for the currency of the payment (only one currency type is allowed for each Mass Payment file):

You must create a tab-delimited file containing your recipients’ information to send a Mass Payment file. A tab-delimited file can be generated from most spreadsheet applications, such as Excel.Column 1: recipients’ email addresses.Column 2: the payment amounts for each recipient.Column 3: the three-letter currency code for the currency of the payment (only one currency type is allowed for each Mass Payment file):

  • EUR for Euro
  • USD for U.S. Dollar
  • GBP for Pound Sterling
  • CAD for Canadian Dollar
  • JPY for Yen
  • AUD for Australian Dollar

Column 4 (optional): a unique identifier for each customer for easier overall record-keeping. The unique identifier must be equal to or less than 30 characters, and must not contain any spaces. Examples of name format: Pitel, John; John_Pitel; JohnPitel.

Column 5 (optional): customized notes about each customer.

How to export a table in comma delimited text format (using mysql):

Here is an example on how to export your mysql tables in the above format:

select field1,field2,’USD’ from paypal_payments into outfile ‘$export_long_name’ fields terminated by ‘\t’ lines terminated by ‘\r\n’”;

in mysql, when you are selecting data from a table, if you add a string in quotes ’string’, it will add on that string in a separate column for each record returned.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
3 comments

Next Page »