DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Languages
  4. How to Optimize PHP Website to Suit Your Goals

How to Optimize PHP Website to Suit Your Goals

In this article, we go over three simples ways to increase the speed and overall performance of your website, using languages like PHP and JSON.

Deborah Belford user avatar by
Deborah Belford
·
Apr. 20, 17 · Tutorial
Like (1)
Save
Tweet
Share
3.34K Views

Join the DZone community and get the full member experience.

Join For Free

Website and software developers like contractworks care about the speed and performance of their website. But most of them don’t usually have enough time to properly optimize their websites. Below are easy steps which are time efficient and will improve a website's performance.

PHP Accelerator

PHP accelerator has been emphasized many times on many computers by different people because it is the first tool to use when you want to optimize your website (my favorite are APC and Zend Optimizer Plus) and some of such computer that is suitable for this purpose can be seen on Techspectacle. You should always keep in mind that the default configuration is not the fastest configuration. One feature of these extensions is that they make sure the cache is up to date by checking up on the file timestamp. Code can’t change immediately in a production situation; therefore, you can disable the feature. It will eliminate the slow 

fstat()

 calls; but an issue is that after every release, you will need to restart all your web servers.

Autoload With the Composer

A Composer is designed to control dependencies but it can also help with the optimization of a website. Even if your code is cached by an accelerator, your website structure can still try to call various functions like “is_readable” and loop through the included path. I had this same problem with Zend Framework 1.12.1. You can fix this problem fast by editing the composer.JSON file.

"autoload": {

"classmap": ["application/", "library/"]

}

Classmap is an array so you can add new paths continuously. Execute the composer to re-establish the autoloader.

$ php composer.phar update

The Autoloader should get much faster because the classmap is going to be cached by the APC.

Serialize Heavy Objects

Creating an instance of an object with a complicated relationship might take a huge amount of time. A perfect example is Zend Framework’s router. This router is a collection of different routes. Each route is an instance of the “Zend_Controller Router_Route”. Creating an instance of a route means executing the route’s constructor (for every instance). Some routes might be storing other routes which add to the execution time of the website. A configuration is normally stored in an INI file or XML which is required to be opened and parsed in the first place.

If the component is sealed and does not have an impact on the environment, you can ignore the execution process and cache the serialized object. When the instance is required, you can get it from a cache and unserialize it. Obviously, the unserialized function does not come without a price. Some developers are of the opinion that it can sometimes be slower than the normal approach. It might also differ across various PHP versions. With the use of a good internet provider service like Century Link Internet, you can simply use the microtime function to measure it:

microtime(true); 

In this router example, you can get a 10% improvement just with this one change.

A major improvement in performance on a non-optimized code is not hard to achieve. The key to success is measuring the problem and applying the 80-20 rule, that is, 80% of problems should be in 20% of the code. XDebug profiler is a tool that will instantly help you highlight where the problems are. Always note to create a profile against your production config.

PHP

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Are the Benefits of Java Module With Example
  • Monolithic First
  • Building Microservice in Golang
  • Introduction to Container Orchestration

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: