Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Saturday, November 17, 2012

Capture the output of var_dump in a string


Introduction

You are programming in PHP and you have an array variable that you’d like to explore at different execution paths. Of course, the best way is to use a PHP debugger like xdebug or Zend Debugger, but, what happens when you’re too lazy to install a debugger? What happens when you don’t want or can’t install a debugger and you just need to check the content of that array by dumping it in your log file? Well, you might think you’re stuck, but, read on…

Thursday, November 8, 2012

Debugging php locally with Zend debugger

My tryst with Facebook app development is taking me to rather not ventured areas of computing.

Latest is debugging php code locally, kindly browse my previous posts to see how to deploy LAMP and create virtual hosts etc.


I was on the lookout of seeing which debugger will suit most on Linux Mint. I found that Zend has a debugger which could be blended with your existing server stack. So I researched and setted it up.

Here is how I did it.


Download the Zend debugger from Zend website here. Select the "Studio Web Debugger" and follow the instructions.

Zend forums has excellent step by step guide on installing the debugger. It can be found here.

Once you have completed the instructions restart your web server.

Now check your error log "/var/log/apache2/error.log", if it has error like following:


"Failed loading /etc/apache2/ZendDebugger.so:  libssl.so.0.9.8: cannot open shared object file: No such file or directory"

install libssl0.9.8 using synaptic.


After that I installed PDT for eclipse and tested the debugger connection in "Debug Cnfigurations..." in Run menu. But the connection failed after searching a bit I found that default port for Zend debugger is 10137, which I changed in eclipse.


Now I am able to debug php in eclipse.

Hope you find this useful, thanks for reading, thanks again to guys for creating such useful software's.


Wednesday, November 7, 2012

Deploying a facebook php app locally on Linux

As in my previous post I said that currently I am having a tryst with Facebook apps. Going further I thought of setting up a local environment where I could make changes locally and see them without uploading on heroku website. I find lots of issues which finally got resolved thanks to generous guys on internet. Following their path I am sharing the complete list of instructions I followed to deploy the Facebook app locally here.

First of all you need to create an app on facebook and host it on heroku website following instructions from following link.

https://devcenter.heroku.com/articles/facebook


Please bear in mind that I chose to deploy the main app locally rather than creating a dev app.

If you find any problem related to ssh keys these commands may help you as they did for me.

 # ssh -vT git@heroku.com  


Above command checks whether a secure connections with heroku site is possible or not. If you get any errors try generating a ssh key and submitting it to heroku.

 # ssh-keygen  
 # heroku keys:add ~/.ssh/id_rsa.pub  


Follow my previous post to create virtual hosts, also don't forget to set facebook app id and app secret in "/etc/apache2/conf/extra/httpd-vhosts.conf" file under VirtualHost tag as below. You can these two from Facebook app site.

 <VirtualHost *:80>  
   DocumentRoot /home/ashish/savefromiad/xxxxxxxxxxxx  
   ServerName mycoolapp-dev.localhost  
   SetEnv FACEBOOK_APP_ID xxxxxxxxxxxxxxxxxx  
   SetEnv FACEBOOK_SECRET xxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
 </VirtualHost  


When I tried accessing the virtual site I got a blank page. I tried searching on internet and got this error in apache error.log at "/var/log/apache2/error.log".

 PHP Warning: require_once(sdk/src/facebook.php): failed to open stream: No such file or directory  


When checked the app directory I found that the php sdk was missing so I got that from their git repository.


and copied that under src/sdk of my app local directory.


Still I kept getting permission error so I changed the owner of the directory to www-data as below.

 # chown -R www-data .  


So the permission error vanished, please bear in mind that may have further repercussions but for now things worked for me. I got this help while setting up Joomla! locally so applied this here as well.

But the errors kept coming, this time like this one.

 Uncaught exception 'Exception' with message 'Facebook needs the CURL PHP extension.  


So checked the php manual and from user notes installed curl and php extension as below.

 # sudo apt-get install curl libcurl3 libcurl3-dev php5-curl  


Even after this it didn't worked so I restarted my laptop and lo!!! it worked.

Update:
Later I noticed that this local running is not same as on heroku.Will see how to resolve and add.
Update 2:
In the mean time you could try heroku eclipse plugin http://eclipse-plugin.herokuapp.com. It greatly eases the change, commit, and test phases. Off course you would be running your actual master code

Thanks for reading and thanks to guys for helping me out. Please don't forget to share if you find this helpful.