Call of Duty 4 (COD4) Modern Combat in Linux
Penulis : Dirman Waktu :Wednesday, March 16, 2016 0 Komentar
sHow To Run Call of Duty 4 (COD4) Modern Combat in Linux
Here in the city I affectionately call Salt Lake Shitty, Utah – it’s about as cold as a witch wearing an iron cupped bra doing push ups in the snow.
To offset this chilly weather, my best friend in the entire world* Yahtzee, who does a little piece for Escapist Magazine every Wednesday called Zero Punctuation warmed up to Call of Duty 4: Modern Combat, calling it a “Pretty Excellent Gun Wank” which in my book means it’s a 5-star title, and worth playing – but only if it runs in Wine.
*I am not actually friends with Yahtzee.
I can hear the groaning and murmurs in the background – stop it!!! All this requires is a little bit of brainless copy and paste from this page into a terminal.
I spent a significant amount of time getting this to work on my own, and apparently I *did not* quote the source of most of what I posted here, for which I apologize. As far as I can recall, I had gone though the process of recompiling Wine with the 3dmark patch, downloading the D3D DLL and found a guide on Ubuntu Forums by ahaslam that had all my work plus more already posted.
Getting COD4 to run in Wine is really no more complicated than say… my tutorial on running all the games in the Orange Box(TF2, Portal, HL2, etc). Getting COD4 up and running takes a little bit more time, since compiling Wine takes the better part of 15 minutes on a relatively fast computer.
On a side note, perhaps the Department of Homeland Security should take a hint from the Wine folks and change their color-coded terrorism threat level matrix, since Wine’s implementation works pretty damn well, if I say so myself.
The story of my life is that I’m ready to kick ass and chew bubble gum, and I’m all out of gum. ARE YOU WITH ME? Let’s go and kill our existing Wine installation, and install a couple tools since we’re going to be rolling our own. Yeehaw!
sudo apt-get remove wine
rm -r ~/.wine
sudo apt-get build-dep wine
sudo apt-get install build-essential checkinstall rar
Next let’s download the source code for Wine, download and apply the “3dmark” diff patch, then recompile Wine. This guide has been updated to use Wine 0.9.56 and several changes have been made after usability testing.
mkdir wine && cd wine
wget http://easynews.dl.sourceforge.net/sourceforge/wine/wine-0.9.56.tar.bz2
tar -xvjf wine-0.9.56.tar.bz2
wget http://bugs.winehq.org/attachment.cgi?id=8548
cp attachment.cgi\?id\=8548 wine-0.9.56/3dmark.diff && cd wine-0.9.56
patch -p1 < 3dmark.diff
./configure --prefix=/usr --sysconfdir=/etc --enable-opengl --with-x
make depend && make
sudo checkinstall
wineprefixcreate
Now, we need to download and install a DirectX DLL file so that everything runs smoothly:
wget http://www.m3fe.com/files/d3dx9_34.zip
unzip d3dx9_34.zip -d ~/.wine/drive_c/windows/system32/
Change Wine to use Windows XP emulation mode, and ddd “d3dx9_34.dll” into the winecfg Library section as a Native dll:
On the Application tab, change the Windows Version to Windows XP
winecfg
On the Application tab, change the Windows Version to Windows XP
Now, I bought the game from Direct2Drive, which means I have an electronic copy – No disc at all, so after extracting the archive of the installation files I opened setup.exe from the directory I extracted it to. If you have the DVD version, just open the setup.exe file from your DVD with Wine.
Installation is a fairly standard process, however I had an issue that cropped up the two times I attempted to test my method, where it failed during the first attempt, but on the second attempt to install the game, it went through flawlessly. I did NOT install PunkBuster because it is not compatible with Wine – yet.
I installed a No-CD patch from Game Copy World just for good measure, and if you’re installing from a CD, you definitely will want this to avoid needing the CD every time you want to play the game or if you get this error like I did:
To install the No-DVD patch, download the iw3sp.exe file from Game Copy World, extract it to your Desktop, then run the following commands which will backup your existing game executable and copy the No-DVD patched one in its’ place:
mv ~/.wine/drive_c/Program\ Files/Activision/Call\ of\ Duty\ 4\ -\ Modern\ Warfare/iw3sp.exe iw3sp.exe.backup
cp ~/Desktop/iw3sp.exe ~/.wine/drive_c/Program\ Files/Activision/Call\ of\ Duty\ 4\ -\ Modern\ Warfare/
Finally, we’re ready to actually run the game.
cd ~/.wine/drive_c/Program\ Files/Activision/Call\ of\ Duty\ 4\ -\ Modern\ Warfare/
wine iw3sp.exe
Unfortunately, a Silver rated game means that some things don’t work, and some configuration changes are needed to make the game run smoothly. Turn off the following options for optimal performance:
Anti-aliasing
Sync Every Frame
Shadows
Specular Map
Depth of Field
Glow
Number of Dynamic Lights
Soften Smoke Edges
Sync Every Frame
Shadows
Specular Map
Depth of Field
Glow
Number of Dynamic Lights
Soften Smoke Edges
Soften Smoke Edges is the most important – Make SURE you turn this off, otherwise the game will not be playable at all.
Here’s a video of the game in action, enjoy!
The video doesn’t really capture the absolutely beautiful graphics COD4 has, it’s a really fantastic game engine.
Artikel Lainnya :
Linux
Backup Your Mobile with Backup Your Mobile
Penulis : Dirman Waktu :Friday, March 11, 2016 0 Komentar
sBackup Your Mobile with Backup Your Mobile
There are countless situations where it’s necessary to back up your device. Whether it be reflashing a ROM or installing a tricky mod, a good a reliable app that backs up your device is always essential to have in the app drawer. Introducing Backup Your Mobile by XDA Forum Member lanx.
Backup Your Mobile is a simple, yet practical app that allow users to backup a whole range of data on the Android device.
Delivered with a straightforward and easily navigable user interface, Backup Your Mobile backs up contacts, call logs, SMS, and system settings among many other options. However, it must be stressed that the app does not back up apps. Users can enable the automatic backup feature with the options to adjust the frequency of backups and the start time of backups. Backup Your Mobile also support backups to cloud services, being Google Drive and Dropbox, so backups don’t take up valuable space on the device or its external storage. Not only uploading to cloud storage, the app also support the reverse, allowing users to download previously uploaded backups from the selected cloud.
With Backup Your Mobile, lanx has definitely developed a useful and practical app for many users. So if you’re a user of Android version 2.2 or newer and interested in Backup Your Mobile, the app can be downloaded for free from the Play store with more details in theoriginal thread.
official : http://www.xda-developers.com
Artikel Lainnya :
Android
Google Ping - Making Blog Ranking 1 on Google
Penulis : Dirman Waktu : 1 Komentar
s
What is a ping? Ping is the meaning of short whistling whistling as we know it could mean calling. So what is Google's Ping? Meaning is calling ping google google search engine robots (search engines) to explore the google website page or blog ping to google it. Actually if a website or blog we've listed and there sitemap (site map) in google via google webmaster tools tools then do not do the robot also ping google will index any new page of our website blog or website.
It's just that there is a shortage if we expect the robot to come alone to index new pages of our blog google robot will then usually come alone without a
definite time limit, meaning can not be sure when it comes, can be quickly and can also be long. Even more quickly if it great, but if this is so old that the problem will result in a new page of our old blog indexed google. If the effect is what we long blog indexed by search engines, especially Google? It is obvious, because it is not or has not indexed the opportunity to bring pengnjung from google search engine will not be around for a new page of our blog has not been indexed by google or google has not entered in the database.
Thus the need for notification to the robot google or commonly called Googlebot with fancy term by the webmaster is a ping to google website and blog so we can quickly spidered by google robots (Googlebot) and rapid entry database google search results. As for how to ping Google consisted of 2 types:
Currently, many services of a website that provides facility services to ping Google. For example ping services include: pingomatic.com mypagerank dam. Many webmasters rarely use the automatic ping service for the automatic and the name of a third party in the sense not of the Google of course will not provide good results. Why? Because it can be a third-party service ping does not work properly and can not summon the robot google. For that many webmasters are advised to manually ping ping manually cause a ping through the service of Google itself and of course the google will prioritize any website or blog that ping from where Google itself from the other third party.
We often do the trick optimization blog post after updating the latest post. Proved after using Google ping ping no later than 24 hours articles are indexed search engine Google.
As for how to automatically ping google, can follow the following ways:
1. Go to Google Ping page: www.googleping.com
2. Fill in the "Blog Details" such as:
Blog Name: Fill with your blog name
Blog Homepage: Fill with your Blog Url
RSS URL (optional): Fill with your blog feed url
Email (required for some): Fill in your email address
3. After all filled out completely, you simply tick the "Service to Ping". Click "Check All" to select all.
4. Once everything is in check, the contents chapta then click on "Send Pings" then ping the blog we will be in the process.
As for how to manually ping to Google is as follows:
1. Click the Google Blog Search Pinging Service
Enter the url page that will ping Google
Finish and wait a while the robots Google or Googlebot will soon visit your blog pages to crawl before you send the url (ping)
Congratulations new page of your blog is listed in the index google and have entered in the Google database.
A few simple ways to do the trick in order to ping a web page / blog we can quickly indexed by the major search engines by Google SE, may be useful.
It's just that there is a shortage if we expect the robot to come alone to index new pages of our blog google robot will then usually come alone without a
definite time limit, meaning can not be sure when it comes, can be quickly and can also be long. Even more quickly if it great, but if this is so old that the problem will result in a new page of our old blog indexed google. If the effect is what we long blog indexed by search engines, especially Google? It is obvious, because it is not or has not indexed the opportunity to bring pengnjung from google search engine will not be around for a new page of our blog has not been indexed by google or google has not entered in the database.
Thus the need for notification to the robot google or commonly called Googlebot with fancy term by the webmaster is a ping to google website and blog so we can quickly spidered by google robots (Googlebot) and rapid entry database google search results. As for how to ping Google consisted of 2 types:
- Automatically ping Google
- Ping Google Manual
Currently, many services of a website that provides facility services to ping Google. For example ping services include: pingomatic.com mypagerank dam. Many webmasters rarely use the automatic ping service for the automatic and the name of a third party in the sense not of the Google of course will not provide good results. Why? Because it can be a third-party service ping does not work properly and can not summon the robot google. For that many webmasters are advised to manually ping ping manually cause a ping through the service of Google itself and of course the google will prioritize any website or blog that ping from where Google itself from the other third party.
We often do the trick optimization blog post after updating the latest post. Proved after using Google ping ping no later than 24 hours articles are indexed search engine Google.
As for how to automatically ping google, can follow the following ways:
1. Go to Google Ping page: www.googleping.com
2. Fill in the "Blog Details" such as:
Blog Name: Fill with your blog name
Blog Homepage: Fill with your Blog Url
RSS URL (optional): Fill with your blog feed url
Email (required for some): Fill in your email address
3. After all filled out completely, you simply tick the "Service to Ping". Click "Check All" to select all.
4. Once everything is in check, the contents chapta then click on "Send Pings" then ping the blog we will be in the process.
As for how to manually ping to Google is as follows:
1. Click the Google Blog Search Pinging Service
Enter the url page that will ping Google
Finish and wait a while the robots Google or Googlebot will soon visit your blog pages to crawl before you send the url (ping)
Congratulations new page of your blog is listed in the index google and have entered in the Google database.
A few simple ways to do the trick in order to ping a web page / blog we can quickly indexed by the major search engines by Google SE, may be useful.
Artikel Lainnya :
Internet
The Social Media Optimisation (SMO) of SEO
Penulis : Dirman Waktu : 0 Komentar
sThe Social Media Optimisation (SMO) of SEO
I was disappointed to miss yesterday’s G+ session with Joshua Berg and Mark Traphagen on social media optimisation (SMO) and search engine optimisation (SEO), unfortunately it was on at 1am London time. However, I have caught up with the YouTube video which is embedded below. It was a great session that covered a lot of incredibly useful information including how embedding lots of links in Google+ can actually reduce your authority. There was so much good stuff I made lots of notes as I listened to the video. I thought I would blog my notes as they might be helpful for people who don’t have an hour and twenty minutes to spare to watch the video. However, I would encourage you to watch the video if you can find the time, it covered a lot of information about social signals and authority which is something I have been interested in for a while.
Social Media Optimisation (SMO) of SEO
Joshua Berg kicked off the session by saying “Social signals provide a much better way of filtering out the noise and improving the quality of search results” and “this is a trend that will continue because it is a much better way of understanding what people really want, which is one of Google’s founding principles.”
Social media and search have grown up separately and Joshua is now predicting the marriage of social media and search, which Joshua calls the SMO of SEO.
These two have needed to come together to make information and knowledge more accessible to everyone which Joshua believes is what Google+ and authorship is designed to do. Google is doing more to understand the context of content which is know as semantic search.
Google Authorship
Mark Traphagen agreed that “as the social web emerges it provides a better set of signals about what is valuable on the web.” Mark then talked through the concept of Google authorship. He explained that the best content on the web is produced by real people. If content is meaningful, real people share it and it would be useful to be able to identify the author of the content, as whenever they write it is likely to be good content. This authorship could be used as a signal in search results.
Google authorship is a means of identifying an author; making a verified connection between them and their data; and tracking how people interact with that content. Google+ is the engine through which Google can achieve this identification verification and tracking. Google+ requires you to be a real person and you need to use a real photo, Google uses facial recognition software plus manual intervention to verify this. With Google+ you can link your profile to content anywhere on the web and to incentivise people to do this they are showing author photos next to search results.
Mark doesn’t believe they have turned this on as a ranking factor yet but Google are collecting the data. Mark cautioned against using your authorship in association with low quality content because if subsequently it gets used as a ranking factor it could have a negative impact.
Social signals and authority
There were a number of questions about what is a social signal.
Signals include connections within Google+ and external connections.
The number of plus ones or number of followers are also signals but Mark believes the key to authority is interactions with higher authority individuals.
The type of links that pass authority include shares, as these become a followed link. Thus if a high authority person shares your link that passes authority to you. If you get a plus mention in the Google+ posts of a higher authority person that will also pass authority to your profile.
By being good networkers and helping people, the audience will share your content and mention you. This will build your authority. In my view this is as it should be as it helps give authority to people who are helpful.
Personalisation
Google and other search engines are moving in to the personalisation of search so that no two people necessarily see the same search results. This happens anyway but if you are logged into Google then your connections and other factors influence your search results. Thus you can influence the search results of your connections on Google+.
Why posting links can give you negative authority
Joshua explained that there are dangers in using Google+ like a bulletin, for example posting a news article every day where you provide an embedded link but don’t say much about the content. Where you do this in Google+, Joshua argues people tend to not interact with the posts. So repeatedly posting links can actually have a negative authority effect as the algorithm will see people posting outside links which people are not interacting with, thus it can’t be valuable content. Thus if you post links in many places and communities, you risk less interaction each time and risk getting negative authority feedback as a consequence.
On the positive side…
Google+ is different as it is actually easy to get noticed very quickly. You can identify people who are posting useful information, place them in influencer circles and start interacting with them in a helpful way. People start to see you are being helpful and becoming part of the community very naturally. The key is again to be helpful to people and add value, the same core lesson which Mark reiterates again and again.
Google+ offers you the opportunity to grow if you want to put in the effort.
Joshua said if you post good content you don’t need to repost or reshare yourself as others will share your content. Mark slightly disagreed with this as he has had good success with reposting the same content at different times of day as people don’t sit watching their streams all day but don’t do it until you have a larger authority. Joshua cautioned though against multiple posting unless it you already know that it is interesting to people.
Advice on posting
During the session someone asked if there is a correct way to post to a brand page and then to a personal page. Mark himself posts more to his personal profile than his brand page. He will republish it through his brand page but at a different time as many people will follow both. I think this is useful advice. You can change your settings so that posts you make to communities do not appear in your personal home stream and post to the community first and then post to your home stream at a later time. Mark also said you can post to your brand page first and then re-share from the brand page at a later time as that reinforces the brand.
Mark explained how you should find a story behind what you do and find a human connection with your content, which he told nicely through a story.
Joshua used a number of terms including relate, captivate, arouse, enjoy, share, acknowledge and contribute. Joshua said though that engagement is key more than content, as if people do not engage with him in Google+ he doesn’t really care too much about the content. It is the engagement that makes the content interesting.
Thanks guys for a great and informative session.
You can see the full video below. For more on authority see my post on content authority and content marketing.
Artikel Lainnya :
Internet
Steps to connect to the Database in java
Penulis : Dirman Waktu : 0 Komentar
sSteps to connect to the Database in java
We have six steps to connect to the database in java. The following steps are used by Java programmers while using jdbc in their java programs.
2. Creating connection
3. Creating statement
4. Executing queries
5. Retrieving the Results
6. Closing connection
1. Registering the driver :
There are several drivers available in the market we should first declare a driver which is going to be used for communication with the database server in a java program.
Registering the driver in 4 ways:
1. By creating an object to Driver class of the driver software.
com.mysql.jdbc.Driver driver obj=new com.mysql.jdbc.Driver();
2. By sending the driver class object to registerDriver () method of DriverManger class.
Example :
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
3. By sending the driver class name directly to forName () method.
Example :
Class.forName(com.mysql.jdbc.Driver());
4. By passing the driver at the time of running the program we can use getProperty () method of the System class.
Example :
String dName = System.getProperty("driver");
Class.forName(dName);
We pass the command line arguments
Example :
c:\> java-d driver = driverclassname program name.
2. Creating connection :
The getConnection () method of DriverManager class is used to establish connection with the database.
We pass three arguments through the getConnection () method.
URL of the Database.
Username.
Password.
Example :
DriverManager.getConnection("com.mysql.jdbc.Driver", "root", "root");
3. Creating statement :
The createStatement () method of Connection interface is used to create Statement.
The object of the statement is responsible to execute queries to the database.
Example :
Statement st=con.createStatement();
4. Executing queries :
The executeQuery () method of Statement interface is used to execute Queries to the database.
This method returns the object of ResultSet that can be used to get all the records of a table.
Example :
public ResultSer rs=st.executeQuery("select * from Emp");
5. Retrieving the Results :
The Result obtained by executing SQL Statements can be stored in an object with the help of interfaces like ResultSet () method, resultSetMetaData () and dataBaseMetaData ().
Example :
ResultSer rs=st.executeQuery("select * from Emp");
while(rs.next())
{
System.out.println(rs.getInt(1)+""+rs.getString(2));
}
6. Closing connection :
By using the close() method of Connection interface is used to close the
connection.
By closing the connection object statement and ResultSet will be closed automatically.
Example :
con.close();
Connect to the database in jdbc :
Example :
package com.wins.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connectiondatabase
{
public static void main(String[] args) throws SQLException
{
System.out.println("This is simple jdbc connection program to connect the mysql database");
String username="root";
// the username is mysql database login username
String password="root";
// the password is mysql database login password
String dbname="test";
// the dname is the database name or schema
String url="jdbc:mysql://localhost:3306/";
// the url is the address of the mysql database with port number the default port number is 3306
Connection conn=null;
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
// registering the driver using second method
conn=DriverManager.getConnection(url+dbname,username,password);
// Creating the connection
System.out.println("successfully connected");
conn.close();
//Closing the connection
System.out.println("connection closed");
}
}
Output :
Successfully connected
source technologiesleader
Artikel Lainnya :
Tips and Tricks
Root Smartfren Andromax C | Hisense AD686g Without PC Easily
Penulis : Dirman Waktu : 0 Komentar
sHow to Root Smartfren Andromax C | Hisense AD686g Without PC Easily
Immediately, for my friend who wanted to directly Root Smartfren Andromax C follow the steps below.But before, my friend had to understand
- Root may cause the warranty void. do Unroot first before bringing to the Service Center Smartfren
- Everything happens because rooting is your own responsibility
Well here's Tutorial or How To Root Smartfren Andromax C | Hisense ad686g Without PC Easily
- Activate the first "Source Unknown or Unknown sources" on the Android dude in a "Settings >> Security"
- Download and Install Applications in Android Framaroot Buddy Framaroot Application Download Here
- After that run the application and then select Superuser or SuperSU you want to use. (select SuperSU recommendations, let's easy to unroot it)
How to Root Smartfren Andromax C
- Further below there are a few methods exploit like Gandalf or Aragon. select "Gandalf"
- If Gandalf does not work, try using Aragon.
How to Root Smartfren Andromax C Without PC
- Upon notification to successful Root, Restart Andromax-C Buddies
- And check whether SuperSU / Superuser has been installed in your Android. or can check by using Root Checker.
Well that's it, Attention All the above is my own doing in my C HP Smartfren Andromax. Prove it in Screenshotnya see, there are two CDMA Signal (X +1 EVDO) and GSM
Commenting please if less obvious
Artikel Lainnya :
Android
HTC One Android 4.2.2 update goes live in UK today (Spain too)
Penulis : Dirman Waktu : 0 Komentar
sHTC One Android 4.2.2 update goes live in UK today (Spain too)
HTC UK has announced that it will begin rolling out the Android 4.2.2 update for HTC One smartphone today. The update will be available over-the-air (OTA) and you can check for it manually by going to Settings > About > Software Updates > Check now.
The update is expected to bring lock-screen widgets, notification bar quick settings and more to HTC One smartphone, you can check out the expected change-log later in the post.
HTC One Android 4.2.2 update change-log:
- Launcher bar enhancements
- Lock-screen widgets
- Home button options
- New quick settings panel in notification shade
- Battery level in status bar
- Gallery app improvements
- AE/AF enhancements in the camera
- New Zoe file format
- Video highlights
- Daydreams
- Widget panel rearrangement
Update: Android 4.2.2 for HTC One live in Spain too
HTC One Glamour Red colour version also available in UK
HTC UK has also confirmed that Glamour Red colour version of HTC One smartphone is now available in shops around UK. The Red version costs same as Sliver or Black variants of the phone. The phone packs 4.7-inch full HD display and is powered by 1.7GHz quad-core Snapdragon 600 processor.
source androidos
Artikel Lainnya :
Android
How to Debug in PHP
Penulis : Dirman Waktu : 0 Komentar
sHow to Debug in PHP
Nobody enjoys the process of debugging their code. If you want to build killer web apps though, it’s vital that you understand the process thoroughly.
This article breaks down the fundamentals of debugging in PHP, helps you understand PHP’s error messages and introduces you to some useful tools to help make the process a little less painful.
Doing your Ground Work
So, with that in mind lets talk about the all too common “I’m getting no error message” issue. This is normally caused by a syntax error on a platform where the developer has not done their ground work properly. First, you should turn display_errors on. This can be done either in your php.ini file or at the head of your code like this:
<?php
ini_set('display_errors', 'On');
Tip: In these code examples I omit the closing (?>) PHP tag. It is generally considered good practice to do so in files which contain only PHP code in order to avoid accidental injection of white space and the all too common “headers already sent” error.
Next, you will need to set an error reporting level. As default PHP 4 and 5 do not show PHP notices which can be important in debugging your code (more on that shortly). Notices are generated by PHP whether they are displayed or not, so deploying code with twenty notices being generated has an impact upon the overhead of your site. So, to ensure notices are displayed, set your error reporting level either in your php.ini or amend your runtime code to look like this:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
Tip: E_ALL is a constant so don’t make the mistake of enclosing it in quotation marks.
With PHP 5 it’s also a good idea to turn on the E_STRICT level of error reporting. E_STRICT is useful for ensuring you’re coding using the best possible standards. For example E_STRICT helps by warning you that you’re using a deprecated function. Here’s how to enable it at runtime:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
It is also worth mentioning that on your development platform it is often a good idea to make these changes in your php.ini file rather than at the runtime. This is because if you experience a syntax error with these options set in your code and not in the php.ini you may, depending on your set up, be presented with a blank page. Likewise, it is worth noting that if you’re setting these values in your code, a conditional statement might be a good idea to avoid these settings accidentally being deployed to a live environment.
What Type of Error am I Looking at?
As with most languages, PHP’s errors may appear somewhat esoteric, but there are in fact only four key types of error that you need to remember:
1. SYNTAX ERRORS
Syntactical errors or parse errors are generally caused by a typo in your code. For example a missing semicolon, quotation mark, brace or parentheses. When you encounter a syntax error you will receive an error similar to this:
Parse error: syntax error, unexpected T_ECHO in /Document/Root/example.php on line 6
In this instance it is important that you check the line above the line quoted in the error (in this case line 5) because while PHP has encountered something unexpected on line 6, it is common that it is a typo on the line above causing the error. Here’s an example:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$sSiteName = “Treehouse Blog”
echo $sSiteName;
echo $sSiteName;
In this example I have omitted the semi-colon from line 5, however, PHP has reported an error occurred on line 6. Looking one line above you can spot and rectify the problem.
Tip: In this example I am using Hungarian Notation. Adopting this coding standard can aid with debugging code while working collaboratively or on a piece of code you wrote some time ago. The leading letter denoting the variable type means that determining a variable type is very quick and simple. This can aid in spotting irregularities which can also help highlight any potential logic errors.
2. WARNINGS
Warnings aren’t deal breakers like syntax errors. PHP can cope with a warning, however, it knows that you probably made a mistake somewhere and is notifying you about it. Warnings often appear for the following reasons:
- Headers already sent. Try checking for white space at the head of your code or in files you’re including.
- You’re passing an incorrect number of parameters to a function.
- Incorrect path names when including files.
3. NOTICES
Notices aren’t going to halt the execution of your code either, but they can be very important in tracking down a pesky bug. Often you’ll find that code that’s working perfectly happily in a production environment starts throwing out notices when you set error_reporting to E_ALL.
A common notice you’ll encounter during development is:
>Notice: Undefined index: FullName in /Document/Root/views/userdetails.phtml on line 55
This information can be extremely useful in debugging your application. Say you’ve done a simple database query and pulled a row of user data from a table. For presentation in your view you’ve assigned the details to an array called $aUserDetails. However, when you echo $aUserDetails['FirstName'] on line 55 there’s no output and PHP throws the notice above. In this instance the notice you receive can really help.
PHP has helpfully told us that the FirstName key is undefined so we know that this isn’t a case of the database record being NULL. However, perhaps we should check our SQL statement to ensure we’ve actually retrieved the user’s first name from the database. In this case the notice has helped us rule out a potential issue which has in turn steered us towards the likely source of our problem. Without the notice our likely first stop would have been the database record, followed by tracing back through our logic to eventually find our omission in the SQL.
4. FATAL ERRORS
Fatal Errors sound the most painful of the four but are in fact often the easiest to resolve. What it means, in short, is that PHP understands what you’ve asked it to do but can’t carry out the request. Your syntax is correct, you’re speaking its language but PHP doesn’t have what it needs to comply. The most common fatal error is an undefined class or function and the error generated normally points straight to the root of the problem:
Fatal error: Call to undefined function create() in /Document/Root/example.php on line 23
USING VAR_DUMP() TO AID YOUR DEBUGGING
var_dump() is a native PHP function which displays structured, humanly readable, information about one (or more) expressions. This is particularly useful when dealing with arrays and objects as var_dump() displays their structure recursively giving you the best possible picture of what’s going on. Here’s an example of how to use var_dump() in context:
Below I have created an array of scores achieved by users but one value in my array is subtly distinct from the others, var_dump() can help us discover that distinction.
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $aUserScores = array('Ben' => 7,'Linda' => 4,'Tony' => 5,'Alice' => '9'); echo '<pre>'; var_dump($aUserScores); echo '</pre>';
Tip: Wrap var_dump() in <pre> tags to aid readability.
The output from var_dump() will look like this:
array(4) { ["Ben"]=> int(7) ["Linda"]=> int(4) ["Tony"]=> int(5) ["Alice"]=> string(1) "9" }
As you can see var_dump tells us that $aUserScores is an array with four key/value pairs. Ben, Linda, and Tony all have their values (or scores) stored as integers. However, Alice is showing up as a string of one character in length.
If we return to my code, we can see that I have mistakenly wrapped Alice’s score of 9 in quotation marks causing PHP to interpret it as a string. Now, this mistake won’t have a massively adverse effect, however, it does demonstrate the power of var_dump() in helping us get better visibility of our arrays and objects.
While this is a very basic example of how var_dump() functions it can similarly be used to inspect large multi-dimensional arrays or objects. It is particularly useful in discovering if you have the correct data returned from a database query or when exploring a JSON response from say, Twitter:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$sJsonUrl = ‘http://search.twitter.com/trends.json’;
$sJson = file_get_contents($sJsonUrl,0,NULL,NULL);
$oTrends = json_decode($sJson);
$oTrends = json_decode($sJson);
echo ‘<pre>’;
var_dump($oTrends);
echo ‘</pre>’;
var_dump($oTrends);
echo ‘</pre>’;
Useful Tools to Consider when Debugging
Finally, I want to point out a couple of useful tools that I’ve used to help me in the debugging process. I won’t go into detail about installing and configuring these extensions and add-ons, but I wanted to mention them because they can really make our lives easier.
XDEBUG
Xdebug is a PHP extension that aims to lend a helping hand in the process of debugging your applications. Xdebug offers features like:
- Automatic stack trace upon error
- Function call logging
- Display features such as enhanced var_dump() output and code coverage information.
Xdebug is highly configurable, and adaptable to a variety of situations. For example, stack traces (which are extremely useful for monitoring what your application is doing and when) can be configured to four different levels of detail. This means that you can adjust the sensitivity of Xdebug’s output helping you to get granular information about your app’s activity.
Stack traces show you where errors occur, allow you to trace function calls and detail the originating line numbers of these events. All of which is fantastic information for debugging your code.
Tip: As default Xdebug limits var_dump() output to three levels of recursion. You may want to change this in your xdebug.ini file by setting the xdebug.var_display_max_depth to equal a number that makes sense for your needs.
Check out Xdebug’s installation guide to get started.
FIREPHP
For all you FireBug fans out there, FirePHP is a really useful little PHP library and Firefox add-on that can really help with AJAX development.
Essentially FirePHP enables you to log debug information to the Firebug console using a simple method call like so:
<?php
$sSql = 'SELECT * FROM tbl';
FB::log('SQL query: ' . $sSql);
In an instance where I’m making an AJAX search request, for example, it might be useful to pass back the SQL string my code is constructing in order that I can ensure my code is behaving correctly. All data logged to the Firebug console is sent via response headers and therefore doesn’t effect the page being rendered by the browser.
Warning: As with all debug information, this kind of data shouldn’t be for public consumption. The downside of having to add the FirePHP method calls into your PHP is that before you go live you will either have to strip all these calls out or set up an environment based conditional statement which establishes whether or not to include the debug code.
You can install the Firefox add-on at FirePHP’s website and also grab the PHP libs there too. Oh, and don’t forget if you haven’t already installed FireBug, you’ll need that too.
In Conclusion…
Hopefully during the course of this article you have learned how to do your ground work by preparing PHP for the debugging process; recognise and deal with the four key PHP error types and use var_dump() to your advantage. Likewise, I hope that you will find Xdebug and FirePHP useful and that they will make your life easier during your development cycle.
As I’ve already mentioned, and I really can’t say this enough, always remember to remove or suppress your debug output when you put your sites into production after all there’s nothing worse than all your users being able to read about your errors in excruciating detail.
Got a great debugging tip to share? Do you use a great little PHP extension that makes your bug trapping life easier? Please tell us about them in comments below!
source blog teamtreehouse
Artikel Lainnya :
Tips and Tricks