Install APC on 64bit WAMP server

I’ve been getting a lot of requests from users to make new post for WAMP server 64bit with APC extension. And so here it is.

First you must go to Wamp server home page. For this tutorial I choose to use this WAMP server with this options:

  • WAMPSERVER (64 BITS & PHP 5.3) 2.2E
  • Apache 2.2.22
  • Mysql 5.5.24
  • PHP 5.3.13
  • XDebug 2.1.2
  • XDC 1.5
  • PhpMyadmin 3.4.10.1
  • SQLBuddy 1.3.3
  • webGrind 1.0

The installation of the WAMP server is easy and I will not explain how to do it.Now lets go and download the apc extension that will work for us. Go to this site and download apc extension Download APC extension. Be careful which one you choose, because there is a lot of APC extensions. First pick that one that is appropriate for your php version. In my case that is PHP 5.3. After that you must choose thread safe or not thread safe APC extension to pick for download.
Now click on your wamp icon and click on Localhost page at the top of the menu. Your browser will open and will open localhost page, find phpinfo() link and click on it. You will be able to see your configuration, find this option “Thread Safety“. If it is enabled then you need Thread safe version of APC extension. So we need this apc extension for download:
APC 3.1.14 beta for PHP 5.3 03/01/2013 53 KB APC
If you want to see more info click on more href to see more info otherwise just click download. Now we have the extension and must put it in the extension folder for php extensions. In my case the folder path is: C:\wamp\bin\php\php5.3.13\ext. Now you need to enable the apc extension. There is two ways to do that:

  • Left click on wamp server icon -> PHP -> PHP extensions and click on php_apc if there is not check mark. Your WAMP server will restart after refresh PHP info page and search for the APC section.
  • Second way to enable php extensions is to open your php.ini file, but be careful the choose correct one. There is one in the php folder and one in the apache folder. Use the second one, which can be found here C:\wamp\bin\apache\apache2.2.22\bin\php.ini. Search for “Windows Extension” at the end of the section add this on new line: “extension=php_apc.dll“. Save the file and restart wamp server.

Now the last step is to have admin page for APC view data, stats, system cache and other options for apc.

    • Go to this page Admin for apc and download as apc.php
    • Save it in your root folder, in my case the path is: C:\wamp\www
    • Open the apc.php with your favorite text editor and change this lanes:
      defaults('ADMIN_USERNAME','apc');    // Admin Username
      defaults('ADMIN_PASSWORD','password');   // Admin Password - CHANGE THIS TO ENABLE!!!
      
    • Now go to http://localhost/apc.php and you should see a page with status of your cache and useful information

That’s all. Good luck.

Posted in Php, Wamp at July 12th, 2013. 1 Comment.

Inserting a text string or paragraph into Zend_Form

If you want to add text after element in form just use description of form element.

textElement = new Zend_Form_Element('someElement'); 
$textElement->setDescription('TEXT'); 

or in the form file:

        $this->addElement(
            'text',
            'some element',
            array(
                'label'         => 'Some element:',
                'description'   => 'TEXT',
            )
        );

If you are wanting something more complex you must define your own decorator.

Posted in Php, Zend Framework at September 27th, 2012. No Comments.

Zend framework MySQL query random records

Hello, sometimes we need a query which will return random rows from table. In your model create this:

    public static function getRandom()
    {
        $model = new self();
        return $model->fetchAll($model->select()
            ->order('RAND()')
            ->limit(8)
            ->from($model)
        );
    }

This will return 8 random rows from the table.
The problem with RAND() function is performing slowly. It needs to assign a random id to each row in database table and find a Unique row. For a small amount of rows will be OK to use RAND() function.
And this work only for MySQL.

That’s all for me. Good luck.

Posted in MySQL, Php, Zend Framework at March 28th, 2012. No Comments.

Install APC on Ubuntu 11.04

Installation of APC on Ubuntu 11.04 is simple, only requires two terminal commands:

sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart

After restart create one php file.

<?php
echo phpinfo();
?>

Check for the apc module.
Good luck.

Posted in Apache, Php, Ubuntu at December 14th, 2011. 1 Comment.

Assigning multi options to drop down in Zend framework

Today I will show you how to add multi options to select tag. It is simple, just add this code to your controller.

    public function testAction() {
        //we are creating Zend_Form instance
        $dropdown = new Zend_Form_Element_Select("dropdown");
        //set label for select tag
        $dropdown->setLabel("Option:");
        //set options
        $dropdown->setMultiOptions(array(
            "Select 1", "Select 2", "Select 3", "Select 4"
        ));
        //add form to the view
        $this->view->form = $form->addElement($dropdown);
    }

And in the view of the controller, show the form.

echo $this->form;

If you check the code, you will see this:

<select name="dropdown" id="dropdown">
    <option value="0" label="Select 1">Select 1</option>
    <option value="1" label="Select 2">Select 2</option>
    <option value="2" label="Select 3">Select 3</option>
    <option value="3" label="Select 4">Select 4</option>
</select>

If you want to specify the values of option tags then use this array:

array(
“1” => “Select 1”,
“2” => “Select 2”,
“3” => “Select 3”,
“4” => “Select 4”
)

And the result will be:

<select name="dropdown" id="dropdown">
    <option value="1" label="Select 1">Select 1</option>
    <option value="2" label="Select 2">Select 2</option>
    <option value="3" label="Select 3">Select 3</option>
    <option value="4" label="Select 4">Select 4</option>
</select>

And that’s all. Good luck.

Posted in Php, Zend Framework at October 15th, 2011. No Comments.

How to set page titles in Zend Framework

Welcome, today I will show you how to set page title on page in Zend Framework.
In Zend Framework, you can set the page title in the controller, like in the example below:

<?php
class Panel_TestsController extends Zend_Controller_Action
{
  public function testAction() {
    //  setting the page title
    $this->_helper->layout()->getView()->headTitle('View all students');
  }
}

or in the view:

/**
 * views/scripts/tests/index.phtml
 */
$this->headTitle('View all students');

And that’s all. Good luck

Posted in Php, Zend Framework at September 17th, 2011. 3 Comments.

How can I get the current module, controller and action in Zend Framework?

Today I will show you how to get current module, controller and action name in Zend Framework. In the default routing, both the module, controller and the action are always passed along with the request. And the code to retrieve them is very simple:

$moduleName = $this->getRequest()->getModuleName();
$controllerName = $this->getRequest()->getControllerName();
$actionName = $this->getRequest()->getActionName();

And that’s all. Good luck.

Posted in Php, Zend Framework at July 27th, 2011. No Comments.

Install APC on WAMP server

The main benefit of APC is to increase the performance of PHP scripts.
How to install APC on WAMP 2.1:
1) Go to http://downloads.php.net/pierre/
2) Download php_apc-3.1-svn20101116-5.3-vc6-x86.zip
3) Copy php_apc.dll to \wamp\bin\php\php5.3.5\ext
4) Enable php_apc extension from WAMP server panel -> PHP extensions

Enable apc extension

5) Open php.ini \wamp\bin\apache\Apache2.2.17\bin and add this:

[APC]
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.max_file_size = 10M
apc.stat = 1

6) Restart Wamp server
7) Open this address http://localhost/?phpinfo=1 in your favourite browser
And check for this section:
Phpinfo page apc
If you see that section, then everything is ok and you successfully installed APC extension on your WAMP server.
UPDATE:
I add new article for WAMP 64bit with APC, you can found it here 64bit wamp

Posted in Php, Wamp at July 6th, 2011. 28 Comments.