Показаны сообщения с ярлыком PHP. Показать все сообщения
Показаны сообщения с ярлыком PHP. Показать все сообщения

среда, 15 мая 2013 г.

Configure PhpStorm for debugging

Params:
IDE: PhpStorm6
OS: Ubuntu 12.10

Problem: 
Configure IDE for debugging.

Solution:
1) At first install and configure XDebug.


 My additional xdebug.ini options:
  • xdebug.remote_enable=On
  • xdebug.remote_host=localhost
  • xdebug.remote_port=9000
  • xdebug.max_nesting_level=250

Do not forget restart your web server with new configuration.
Also you can check if XDebug is used in phpinfo output.

2) Install and configure "Xdebug Helper" plugin in browser(chrome for example)
I using https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc
Configuration options for it:
IDE key Other:PHPSTORM1
Or you can try another key from PhpStorm documentation page:
http://www.jetbrains.com/phpstorm/marklets/

3) Configure PhpStorm:
Add your app server: File -> Settings -> PHP -> Servers (Debugger: Xdebug)
Configure debug options: File->Settings->PHP->Debug
  Xdebug | debug port - 9000
  Xdebug | Can accept external connections - checked


Debuging
Run->Break at first line in PHP scripts - check it
Run->Start Listen PHP Debug Connections - enable listener
Go to debugging page in browser.
Click on gray bug icon and enable Debug.
After these actions all should be ready, so reload page(or send a form, or click on link, ...) and debug will start.

Thanks to authors from these resources:
http://icephoenix.us/php/how-to-setup-local-php-debugging-with-phpstorm-and-xdebug/
http://blog.jetbrains.com/webide/2011/02/zero-configuration-debugging-with-xdebug-and-phpstorm-2-0/
http://blog.jetbrains.com/webide/2011/03/configure-php-debugging-in-phpstorm-2-0/

четверг, 13 сентября 2012 г.

Enable $HTTP_SERVER_VARS and $HTTP_GET_VARS in PHP5

Params:
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch

Problem:
In php4 project not defined variables $HTTP_SERVER_VARS and $HTTP_GET_VARS

Solution:
Enable php directives register_globals and register_long_arrays
You can do it in your php.ini configuration file, but the best way do it in .htaccess file in your specific project.

пятница, 31 августа 2012 г.

Symfony2 composer install error

Params:
PHP 5.3.10-1ubuntu3.2
Symfony 2.1 RC2

Problem:
After command
> php composer.phar install
I have error:
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for jms/security-extra-bundle == 1.2.9999999.9999999-dev -> satisfiable by jms/security-extra-bundle 1.2.x-dev.
    - Can only install one of: jms/security-extra-bundle dev-master, jms/security-extra-bundle 1.2.x-dev.
    - Installation request for jms/security-extra-bundle == 9999999-dev -> satisfiable by jms/security-extra-bundle dev-master.

Solution:
1) Remove composer.lock file from your project directory
   > rm composer.lock
2) Re-install all packages again, run command:
   > php composer.phar install

It will take some time, but the problem will be solved.

вторник, 29 мая 2012 г.

суббота, 4 февраля 2012 г.

Magento disable user subscribe success email notification

Params:
Magento 1.6.0

Problem:
In Magento admin you can not disable email notification when user subscribe.  So, look to this solution

Solution:
Find script:
/app/code/core/Mage/Newsletter/Model/Subscriber.php
and comment folloving line in function subscribe($email) :
$this->sendConfirmationSuccessEmail();


PS:
This is bad solution, because  when you upgrade your store to the new version
those changes will be overwritten. If you not so lazy, create package for yourself ;)

пятница, 3 февраля 2012 г.

Magento change amount of emails sended at once

Params:
Magento 1.6.0

Problem:
In Magento I need decrease of emails count wich will be send by cron at once.  Set this value to 8
and send emails every 5 minutes against default 15.

Solution:
Find and edit the following scriots by example.

Change count of emails in one action:
app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
$countOfSubscritions = 8;
app/code/core/Mage/Newsletter/Model/Observer.php
$countOfSubscritions = 8

Change newsletter exec cron  time interval:
/app/code/core/Mage/Newsletter/etc/config.xml
<crontab><jobs><newsletter_send_all><schedule>
<cron_expr>*/5 * * * *</cron_expr>


PS:
This is bad solution, because  when you upgrade your store to the new version
those changes will be overwritten. If you not so lazy, create package for yourself ;)

понедельник, 9 января 2012 г.

Configure Zend Debugger

Params:
Linux Gentoo 3.1.6
PHP 5.3.8-pl0-gentoo
Apache 2.2.21-r1

Problem:
Need to configure Zend Debugger.

Solution:
1) Download Zend Debugger from site zend.com
2) Unpack archive to the temporary folder.
3) Find ZendDebugger.so file with version compatibale to your PHP version
For example, I have PHP version 5.3.8 so my ZendDebugger.so file located in 5.3.x folder.
4) Copy ZendDebugger.so to the folder accesibale by apache.
For example: /home/<user_name>/Applications/ZendDebugger/ZendDebugger.so
5) Edit php.ini. Location of php.ini depends by system. For Gentoo is here: /etc/php/apache2-php5.3/php.ini
6) Add following lines to the end of php.ini:

[Zend]
zend_extension=/home/<user_name>/Applications/ZendDebugger/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1
zend_debugger.expose_remotely=always
About this and additional options you can read in internet.
7) Restart the apache. In gentoo just execute /etc/init.d/apache2 restart
8) Check debugger. Look to the phpinfo() if all "ok!" you will see section "Zend Debugger" with config options.
9) Fix errors. If you can't see "Zend Debugger" section look to the apache error log file and fix the errors.
Log file in Gentoo: /var/log/apache2/error_log
In my case I have this errors:
* Failed loading /home/<user_name>/Applications/ZendDebugger/ZendDebugger.so:  libssl.so.0.9.8: cannot open shared object file: No such file or directory
* Failed loading /home/<user_name>/Applications/ZendDebugger/ZendDebugger.so:  libcrypto.so.0.9.8: cannot open shared object file: No such file or directory
So I create soft links to the existing libs "libssl.so.1.0.0" and "libcrypto.so.1.0.0"
> ln -s /usr/lib/libssl.so.1.0.0 /home/<user_name>/Applications/ZendDebugger/
> ln -s /usr/lib/libcrypto.so.1.0.0 /home/<user_name>/Applications/ZendDebugger/
links must be in the same folder with ZendDebugger.so

That's all.

суббота, 7 января 2012 г.

Configure Apache to interpret PHP scripts

Params:
- Linux solar 3.1.6-gentoo #16 SMP Thu Jan 5 14:49:10 GMT 2012 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ AuthenticAMD GNU/Linux,
- PHP 5.3.8-pl0-gentoo,
- Apache/2.2.21 (Unix)

Problem:
Apache not interpret php scripts, theirs content printed in browser.

Solution:
Edit apache config file /etc/conf.d/apache2 (don't forget this is gentoo!)
Find string where defined parameter APACHE2_OPTS and add "-D PHP5" to his value.

воскресенье, 25 декабря 2011 г.

PHP sessions across sub domains

Params:
PHP-5.3, Apache-2.2

Problem:
I need a single session for mysite.com and admin.mysite.com domains. I would login on main domain mysite.com, and will be already authorized on sub domains like admin.mysite.com.


Solution:
In script before session start need too setup this session parameters:
session.cookie_path = "/"
session.cookie_domain = ".mysite.com" - dot at the beginning is important, it specify use same sessions on sub domains

Example:
Example for Zend Framework application.


Define site domain name value:
*** public/index.php ***
...
defined('SITE_DOMAIN_NAME')
|| define('SITE_DOMAIN_NAME', (getenv('SITE_DOMAIN_NAME') ? getenv('SITE_DOMAIN_NAME') : 'mysite.com'));
...
It seems, if server value SITE_DOMAIN_NAME is not defined, craete it. We will use it in config file.

You can define SITE_DOMAIN_NAME in .htaccess file, Anyway he need to be configured on every server separately.

*** public/.htaccess ***
...
SetEnv SITE_DOMAIN_NAME mysite.com
...

Further I set session values in config file
*** application/configs/application.ini ***
[production]
...
local.session.cookie_path = "/"
local.session.cookie_domain = "." SITE_DOMAIN_NAME
...
This line  "." SITE_DOMAIN_NAME  is equal to ".mysite.com"

And in Bootstrap.php wee initialize session.
*** application/Bootstrap.php ***
...
protected function _initSession()
{
$localCfg = new Zend_Config($this->getOption('local'), true);
Zend_Session::setOptions($localCfg->session->toArray());
Zend_Session::start();
}
...

пятница, 23 декабря 2011 г.

Zend Framework, bind subdomains to modules

Params:
Zend Framework 1.11, PHP-5.3, Apache 2.2, local pc with Gentoo on board.

Problem:
I want to bind subdomains to certain module of Zend Framework application.
Example: 
http://mysite.com - follow to default module of my app.
http://admin.mysite.com - follow to admin module.
Controllers, actions and params may be various(global variables also):
http://admin.mysite.com/index/index/foo/bar/......
etc.

Solution:
1) Create site with default Zend Framework module structure.
/var/www/mysite.com/
   application/
      configs/
      modules/
         admin/
            controllers/
            views/
         default/
            ......
      Bootstrap.php
   ......

2) Bind DocumentRoot folder of mysite.com, www.mysite.com, admin.mysite.com to the same folder. In my case it's:
/var/www/mysite.com/public

3) In Bootstrap.php file init application router:
 protected function _initRouter()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$hostnameDefaultRoute = new Zend_Controller_Router_Route_Hostname(':module.mysite.com'  , array('module' => 'default'));
$router->addRoute('default', $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*', array('lang' => 'en', 'controller'=>'index', 'action'=>'index'))));
  $hostnameDefaultRoute = new Zend_Controller_Router_Route_Hostname('mysite.com'  , array('module' => 'default'));
$router->addRoute('www', $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*', array('lang' => 'ru', 'controller'=>'index', 'action'=>'index'))))
->addRoute('login'  , $hostnameDefaultRoute->chain(new Zend_Controller_Router_Route_Static('login',   array('controller' => 'user', 'action'=>'login'))));
// routes for admin area
$hostnameAdminRoute = new Zend_Controller_Router_Route_Hostname('admin.mysite.com', array('module' => 'admin'));
$router->addRoute('admin' , $hostnameAdminRoute->chain(new Zend_Controller_Router_Route(':lang/:controller/:action/*',   array('lang' => 'en', 'controller'=>'index', 'action'=>'index'))))
->addRoute('settings' , $hostnameAdminRoute->chain(new Zend_Controller_Router_Route_Static('settings', array('controller' => 'config', 'action' => 'list'))));
}
==================================================================
In a result will work this url's:
mysite.com/ -> Module: default, IndexController, indexAction, lang: en
mysite.com/en/index/index -> Module: default, IndexController, indexAction, lang: en
mysite.com/en/index/index/foo/bar -> Module: default, IndexController, indexAction, lang: en , params: foo = bar
mysite.com/login -> Module: default, UserController, loginAction
admin.mysite.com -> Module: admin, indexController, indexAction, lang: en
admin.mysite.com/en/ -> Module: admin, indexController, indexAction, lang: en
admin.mysite.com/settings -> Module: admin, configController, listAction

4) Also you can use route names in view helper URL. In view script:
echo $this->url(array(), 'www') will output 'mysite.com/en/index/index'
echo $this->url(array('foo' => 'bar'), 'www') will output 'mysite.com/en/index/index/foo/bar'
echo $this->url(array(), 'login') will output 'mysite.com/login'
echo $this->url(array('page' => 1), 'admin') will output 'admin.mysite.com/en/index/index/page/1'
echo $this->url(array(), 'settings') will output 'admin.mysite.com/settings'
Also you can specify controllers and actions
echo $this->url(array('controller' => 'post', 'action' => 'list'), 'www') will output 'mysite.com/en/post/list'
echo $this->url(array('action' => 'print', 'id' => 2), 'admin') will output 'admin.mysite.com/en/index/print/id/2'

воскресенье, 18 декабря 2011 г.

Magento, change emails count in newsletter queue

Params:
Magento 1.6.0

Problem:
When cron execute newsletters, the count of emails which will be send is limited to 20 per request.

Solution:
Notice: This is bad solution!
Edit script app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php
Find string :
$countOfSubscritions = 20;
and set the value which you need. For me is "8" - limit of my hosting (emails count per request).

вторник, 1 ноября 2011 г.

PHP sendmail, save mails in local filesystem folder

Params:
OS: Gentoo
Language: PHP 5.3.8

Problem:
Save mails sended from PHP script in local filesystem folder.
View them by KMail

Solution:
Make all changes relative to your distro.
1) Create script fakesendmail.sh

#!/bin/sh 
prefix="/home/<my_username>/temp/sendmail/new"
numPath="/home/<my_username>/temp/sendmail"
if [ ! -f $numPath/num ]; then
    echo "0" > $numPath/num
fi
num=`cat $numPath/num`
num=$(($num + 1))
echo $num > $numPath/num 
name="$prefix/letter_$num.txt"
while read line
do
     echo $line >> $name
done
chmod 777 $name


/bin/true


I saved it in folder /home/<my_username>/Applications/

Don't forget set appropriate pathes in script.

2) Make this script executable: console> chmod +x fakesendmail.sh


3) Create folders for mails: 


console> mkdir 
/home/<my_username>/temp/sendmail/


console> mkdir 
/home/<my_username>/temp/sendmail/cur


console> mkdir 
/home/<my_username>/temp/sendmail/new


console> mkdir 
/home/<my_username>/temp/sendmail/tmp


4) Change folder properties: console> chmod 777 -R 
/home/<my_username>/temp/sendmail/


5) Make changes in php.ini file (on gentoo: /etc/php/apache2-php5.3/php.ini)


Change path to sendmail script to our new script:


sendmail_path = /home/<my_username>/Applications/fakesendmail.sh
6) Open KMail and create new incoming account.
Kontact->Settings->Configure KMail->Accounts->Add Account
In opened window choose "Maildir mailbox" and set appropriate folder "
/home/<my_username>/temp/sendmail"



воскресенье, 30 октября 2011 г.

Regular expression to ignore escaped quotes within quotes

Params:
Language: PHP

Problem:
I have string:
$text = '[[["my tree \",and to and \"\" something \'\"else","moe derevo \" , a takzhe i\" \"nechto \" drugoe",""]],,"en",,[["en"]],2]';
I need only quoted part of it:  my tree \",and to and \"\" something \'\"else


Solution:

$pattern = '/"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"/imsu'; // Use this regular expression
$match = '';
preg_match($pattern, $text, $match);
var_dump($match[1]);

And you will see: my tree \",and to and \"\" something \'\"else

среда, 19 октября 2011 г.

Magento Admin Notification bugfix

Magento v.1.6
Trouble:
Every time when I am login to the admin panel see this message:"Reminder: Change Magento`s default phone numbers and callouts before site launch"
It's really damn annoying.


Sollution:
Copy the file app/code/core/Mage/AdminNotification/Model/Resource/Inbox.php
to app/code/local/Mage/AdminNotification/Model/Resource 
Create these folders if they does not exists.
And edit this php script.
Line 102. Find:
$select $adapter->select()
                ->from($this->getMainTable())
                ->where('url=?'$item['url']);
Replace it by:$select $adapter->select()
                ->
from($this->getMainTable())
                ->
where('url=? OR url IS NULL'$item['url'])
                ->
where('title=?'$item['title']);

Delete all your notifications.


Thanks to Payserv http://www.magentocommerce.com/boards/viewthread/246247/

четверг, 31 марта 2011 г.

Zend_Validate_Db_RecordExists with doctrine

Validator Code:
<?php
class Validator_NoRecordExists extends Zend_Validate_Abstract
{
      private $_table;
      private $_field;

      const OK = '';

      protected $_messageTemplates = array(
          self::OK => "'%value%' allready in database"
      );

      public function __construct($table, $field) {
            if(is_null(Doctrine::getTable($table)))
                  return null;

            if(!Doctrine::getTable($table)->hasColumn($field))
                  return null;

            $this->_table = Doctrine::getTable($table);
            $this->_field = $field;
      }

      public function isValid($value)
      {
            $this->_setValue($value);

            $funcName = 'findBy' . $this->_field;

            if(count($this->_table->$funcName($value))>0) {
                  $this->_error();
                  return false;
            }

            return true;
      }
}

Use like:
$this->addElement('text', 'username', array(
      'validators' => array(
            array(
                  'validator' => new Validator_NoRecordExists('User','username')
            )
      )
));

 

четверг, 17 марта 2011 г.

Configure xDebug with Zend Studio or Eclipse IDE

system: gentoo | php: 5.3.3 | xdebug: 2.0.5

1. Install xdebug: emerge dev-php/xdebug-client -av
2. Edit php.ini: Include xdebug configuration file in php.ini.
    • create and put xdebug.ini file in directory: /etc/php/apache2-php5/ext/
    • create soft link: ln -s /etc/php/apache2-php5/ext/xdebug.ini /etc/php/apache2-php5/ext-active/
    •  xdebug.ini file content:  
    [xdebug]
    zend_extension=/usr/lib/php5/lib/extensions/no-debug-zts-20090626/xdebug.so
    xdebug.auto_trace="0"
    xdebug.trace_output_dir="/tmp"
    xdebug.trace_output_name="trace.%c"
    xdebug.trace_format="0"
    xdebug.trace_options="0"
    xdebug.collect_includes="1"
    xdebug.collect_params="0"
    xdebug.collect_return="0"
    xdebug.collect_vars="0"
    xdebug.default_enable="0"
    xdebug.extended_info="1"
    xdebug.manual_url="http://www.php.net"
    xdebug.max_nesting_level="100"
    xdebug.show_exception_trace="0"
    xdebug.show_local_vars="0"
    xdebug.show_mem_delta="0"
    xdebug.dump.COOKIE="NULL"
    xdebug.dump.ENV="NULL"
    xdebug.dump.FILES="NULL"
    xdebug.dump.GET="NULL"
    xdebug.dump.POST="NULL"
    xdebug.dump.REQUEST="NULL"
    xdebug.dump.SERVER="NULL"
    xdebug.dump.SESSION="NULL"
    xdebug.dump_globals="1"
    xdebug.dump_once="1"
    xdebug.dump_undefined="0"
    xdebug.profiler_enable="0"
    xdebug.profiler_output_dir="/tmp"
    xdebug.profiler_output_name="cachegrind.out.%p"
    xdebug.profiler_enable_trigger="0"
    xdebug.profiler_append="0"
    xdebug.profiler_aggregate="0"
    ;xdebug.remote_enable="0"
    xdebug.remote_enable=On
    xdebug.remote_handler="dbgp"
    xdebug.remote_host="localhost"
    xdebug.remote_mode="req"
    ;xdebug.remote_port="9000"
    xdebug.remote_port=9000
    xdebug.remote_autostart="0"
    ;xdebug.remote_log=""
    xdebug.remote_log="/var/www/xdebug.log"
    xdebug.idekey=""
    xdebug.var_display_max_data="512"
    xdebug.var_display_max_depth="2"
    xdebug.var_display_max_children="128"
    3. Check  phpinfo(). If all OK, you will see  "xdebug section"
    4. Configure Zend Studio.
    • Open your project in Zend Studio
    • In the main menu select Project->Properties
    • On the left side of the window select "PHP Debug" and then click on "Configure Workspace Settings"
    • On the "PHP Debugger" dropdown select Xdebug and click "Apply"
    • Click "Configure" to the right of Xdebug in the same window.
    • Select Xdebug and click "Configure".
    • On the "Accept remote session(JIT)" select "any" and click "OK". This is extremely important and this is where most people get stuck.
    5. Debug!!! :)

    very helpfull for me!

    среда, 9 февраля 2011 г.

    Apache segmentation fault on local server

    Problem in PHP while init session in script.
    Solution:
    1. Change configs: /etc/php5/apache2/conf.d/suhosin.ini /etc/php5/conf.d/suhosin.ini
    2. Uncomment and edit line: suhosin.session.encrypt = off
    3. Restart apache: /etc/init.d/apache2 restart
    URL:
    Working for me!

    Also solution update your apache server to newer version! Realy helps! :)