Using Return Codes in PHP


I will show you how to execute a command on your server using system(). I will show you how to check if the command was successful using its return value.

To demonstrate this functionality we'll write a short script restarts your web server. Before restarting the server it will verify the configuration file is valid.

To execute a command we use the system() function. This function accepts as its first argument the command to execute, while the second argument is a variable you pass by reference that the return value is written to.
Note: You can also use functions such as exec() or passthru() if you need to access output from the program, but to keep things simple we'll ignore these functions.

The following listing shows how you to call system().
Listing 1 Accessing and outputting the return value from system() (listing-1.php)

<?php
system('/path/to/someCommand', $retval);
echo "Return value: " . $retval;
?>

If a command-line program has been written correctly, it will exit with a status code of 0 when the program executes correctly, or it will exit with a non-zero value when something does not work correctly.

The following listing shows a basic check of the return value. The specific error that has occurred will depend on the command being run.
Listing 2 Checking the return value and acting accordingly (listing-2.php)

<?php
system('/path/to/someCommand', $retval);

if ($retval == 0) {
echo "Executed correctly\n";
}
else {
echo "Some error occurred: " . $retval;
}
?>

To demonstrate this, we'll write a short script that calls makes use of the apachectl program. This is used to control an Apache installation (start / stop / restart the server). If you run this command with an argument of configtest it will tell you if the configuration is valid. If you run it with an argument of graceful it will restart the server (gracefully - that is, it will complete any active requests).

When you run apachectl configtest it will tell you if an error occurs, but additionally, it will exit with a code of 8 (you can see this documented inside the apachectl script).

Therefore, you can run this command and check if the configuration file is valid. If it is, we'll restart the server, if not, we won't. The following listing demonstrates this.
Listing 3 Restarting your Apache server if the configuration is valid (listing-3.php)

<?php
$ctl = '/usr/local/apache/bin/apachectl';

system($ctl . ' configtest', $retval);

if ($retval == 0) {
system($ctl . ' graceful');
}
else {
echo "Configuration error, unable to restart\n";
exit($retval);
}
?>

In this script we chained the return value. That is, when an error occurred we also exited with that return code. That way, if yet another script uses our PHP script they can also check the error code if required.

That's all there is to it! You could extend this script by checking the return value of the second command also, since this call can also fail.

Improving Web Performance from Page Components

On a web page images, flash, style sheets and scripts are some of the components that take time to load. For increasing the site load time, we might have to keep the site simple and reduce the number of web components on a page. The Http request/replies have to be kept at a minimum for optimum web performance.

The web page design needs to be simple by reducing the number of page components that take time to load. CSS sprites are one of the most preferred methods that reduce the number of image requests.

Response times are often impacted by user's proximity on web servers. When looked upon content for a solution, deploying content to server across multiple geographies will make the pages load faster. This can also be made unique to geography, looking upon the local market for the product or service, as this would definitely boost online businesses locally for their geographies.
Changing the architecture of the site can be a daunting task, synchronizing session state and replicating the database transactions across al the server locations. On an average, 80 to 90% of the time is spent on loading the components of the page. Its always a god idea to disperse static content rather then redesigning your site applications architecture. The front end engineers that care about web performance want a page to load progressively as soon as possible. This is very essential for the users who are looking out for a lot of content are on very low internet speeds.

Monitoring website applications in terms of performance should be focused in order to have optimum performing site. Web application monitoring solutions should be used to have comprehensive monitoring of web applications. Web performance is directly dependent on monitoring the website with different aspects in mind regarding all the components used on the website.

How to make 'her' fall in love with you

Searching for ways to make a woman fall in love with you can easily drive you up the wall. For a lot of men, just like you, women can be a little bit of a mystery. One moment you think that you are doing okay with a woman, and then the next moment, you are wondering if she is really into you at all. Is there a way that you can make sure that you can make her fall for you?
Here are some ways to make a woman fall in love that should get you going:

1. Be the kind of guy that she can feel secure with.
The only way to really make a woman feel this way is for her to see that YOU are a secure man. When a woman can sense that you are nervous or insecure around her, you are doing nothing to make HER feel security when she is with you. Don't assume that you have to act super macho to make a woman feel protected by you. You just have to leave her with the impression that she is with a confident alpha male that has no insecurities at all.

2. You have to be spontaneous with a woman.
To be honest, most guys ARE pretty boring. When they want to take a woman out on a date, they will do the tried and true dinner and a movie thing. You want to get used to being a little more spontaneous and think outside of the box once in a while when you are with a woman. You don't want her to be able to read your every move even before you make it. You want to be able to catch a woman by surprise and make her wonder what is going to happen next when she is with you.

3. You have to be able to go beyond the friend zone with a woman.
Being polite and being friendly is all well and good, but if you want to make a woman fall for you, if you want her to want you, then you have to go beyond that friend zone with her. If you hesitate to do this, or if you never really get beyond this stage with her, then you are only going to end up disappointed when you find out that she does not feel the same way about you that you do about her. Most men have been in this situation before, and you have to realize that it's a trap.

Resolving Error 8906 in MS SQL


In MS SQL Server database, a PFS (Page Free Space) page has one byte for each of the pages existing in the file interval it maps. This byte contains a bit that indicates that the associated page is a mixed page. An IAM page includes a mixed page array, which is an array of eight page IDs, to keep the mixed pages that have been allocated to the index. In some cases, when the database goes corrupted, the page containing 'mixed page' bit is not recognized correctly. Thus, you can detect such specific cases of database corruption and, take corrective measures for MS SQL Repair.

Most of the SQL database corruption problems can be analyzed and detected by running DBCC CHECKDB command. Let's consider the below error message, which typically appears when the discussed problem occurs. When you run DBCC CHECKDB command to check the integrity of database, following error might pop up:


Server: Msg 8906, Level 16, State 1, Line 0
Page P_ID in database ID DB_ID is allocated in the SGAM SGAM_P_ID and PFS PFS_P_ID, but was not allocated in any IAM. PFS flags 'PFS_FLAGS'.

Cause

Error 8906 is most likely to occur when a page with 'mixed page' bit set up in PFS byte has not been detected as an IAM page or in a mixed page array of an IAM page, which indicates database corruption.

Solution

If you encounter error 8906 after running DBCC CHECKDB on your SQL Server database, apply the below measures to solve it:

Run hardware diagnostics to isolate hardware-related problems. Corrupted hardware components are known to cause these issues if database corruption persists.
Restore the database from last good backup available.

If no clean backup is available, run DBCC CHECKDB without any repair clause to know the extent of damage and required SQL Repair clause. Again run DBCC CHECKDB command with the recommended repair clause. Make sure to backup your database before executing the repair command, in order to avoid post-crash results.
Use a third-party SQL Repair utility, in case DBCC CHECKDB doesn't work.


For best results, it is recommended to use Stellar Phoenix SQL Recovery software. Designed to run powerful and safe scanning algorithms, this SQL Repair utility can restore all database objects in a simple way. The application supports MS SQL Server 2008, 2005, and 2000.