Debug PHP and Control Flow? - php

I am an autodidact so dont know much about conventional web development however, I have wrote a complete social networking website yet I dont know how to debug. My website has some problems and I need to learn debuggin things around/
First of all I need instructions how to install Xdebug on WAMP (since I use phpDesigner). I tried a lot using tutorials on the web everytime I get a new error. I also tried puting it in the /ext/ directory and activating it from the WAMP PHP Extensions menu. Doesnt Work!
So if anyone odf you out there uses PHPDesigner with Xdebug (not the package that comes along, rather install it on WAMP) please help me and I would really be grateful. BTW PHP version is 5.3.0
Next thing is this is how is the the control flow of my website :-
htaccess -> redirect everything to index.php if file doesn't exist.
index.php ->
include all libraries (__autoload).
initialize classes.
Get the $_SERVER['REQUEST_URI'] to get the $page.
If $page is found
Check if the user is logged in,
if yes then include view/$page.php
or else redirect to login.php page
If page is not found then
redirect to 404.php
Is this control flow good for debugging? because I really cant understand the real MVC concept so I created something like this.

There is a tutorial for installing XDebug for use with phpDesigner here.
MVC is an organizing principle (also called a "design pattern"). It can be helpful keeping logically similar parts of a project together, and encouraging clean interfaces between them, but—especially for low complexity projects—strict MVC modeling isn't always an improvement.
You ask:
Is this control flow good for debugging?
Debugging is to identify flaws in programs. Writing a program to be easy to debug is like intentionally driving a car off the left side of the road so you'll know where to direct an ambulance to find you. Granted—there are small things which can be done to greatly improve debugability. But the point is to architect any control structure so it naturally expresses the algorithm. By doing that, it is far more likely to avoid the need to debug. Anything you can do to write correctly functioning code is justifiable.
Your control flow is clear to me. I wouldn't have any qualms about working on it.

Use xDebug.
Its very easy to install and use.
and you can download xDebug from here http://www.xdebug.org/
step by step tutorial for setup xdebug with WAMP is available at sachithsays.blogspot.com/

Related

How to work on a website which is selected as down mode?

I use Laravel framework and as you know there is a something named Maintenance Mode. That's perfect for debugging the online version of your website. I mean, you can simply deactivate your website to open by this command:
php artisan down
Also you can make it alive again by this one:
php artisan up
Ok all fine .. My question is, how can I see the result of debugging on my website in this case? I mean, when my website is down for my website's user, I need to load it and do some tests on it .. but sadly it is also down for me.
Anyway, I'm looking for an approach to shut down my website for everybody except myself. Any idea?
Create a local development environment, preferably with something like Homestead or Valet.
Basic rule of thumb on the internet: if you can see it, someone else can.
The local environment also gives you the benefit that should you mess something up, no end user will experience that.

PhpBB's automod like software for php

I have looked and looked all over to find a way to make something similar to PhpBB's automod system they use for their software.
I cannot seem to find anything similar to this with the whole xml find and replace code updater and mod installer.
I may just be typing in the wrong keywords in Google, but does anyone know of any system like this available before I start trying to make my own?
EDIT: I mean more like a code updater. For example find and replaces in a php file.
FIND:
?>
ADD BEFORE:
echo "this is text added before the ?>";
I realize this could be done with str_replace but there is surely a system out there that already does this reliably.
The reason that a system doesn't exist outside of phpBB is because it's an incredibly poor way to manage modifications. Your question does not make it clear what you want to gain from this, but since it is your own code, you should definitely not look to copy something so awful.
For “patching” code
If you want the ability to apply updates to your code, then you should look at handling it through version control. For instance, you could develop and test in a local git repository, and once you are happy, push the changes to the server. You have many options here from a basic update script to a fully-fledged Continuous Integration solution.
phpBB have implemented a solution for patching code on your live site via a Web interface, which has many issues with security, verifiability and maintainability among others.
For exposing “plugin” functionality
If you want the ability to register plugins in parts of your code, then you should architect your code as such to allow it to be handled easily. Wordpress, MediaWiki and other projects can help you write such a structure.

debugging a Yii web application using Zend Debugger in Eclipse

I have Zend debugger running successfully in Eclipse but I don't understand how to debug a Yii project. I.e, I can debug a single page PHP script but I don't know what the configuration options are supposed to be for a Yii web application.
For example, I was thinking the Controller file would be the file I would select to actuall debug but it says the file can't be found. I've attached a screen shot of what the options are.
I've used the Firefox Zend Debugger extension and that works great. Now, I just want to know how to do the equivalent of that in Eclipse.
The basic options are: File and URL
Have you debugged other applications using Eclipse? If so, it shouldn't be much different:
I'm usually debugging on /, meaning I login to the application, go wherever I need to, then prepare the debugged scenario (including breakpoints where appropriate). Next, I run a "general" debug session -> a new tab is opened on the browser. I ignore this tab and instead go back to the tab where I prepared the scenario I want to debug and continue there.
I usually go with marking / or /index.php as the "debug entry point" (or whatever the term is). If needed (I don't think I needed to with Yii), I would have config some "paths" that tell the IDE that "/" is translated/represented by HTDOCS. Again, I don't think I needed to with Yii (but I debugged little with Yii thus far).
I once had a blog post on debugging Drupal with PDT (which is Eclipse) and xDebug (which is an alternative to the Zend Debugger and essentially the same). You might find it useful: link.
Good luck!
When in a framework, work within the framework rules. If something's not working, don't try to review the code step-by-step. That's unproductive, because you will pass through dozens of encapsulated functions with no discernible order. Yii is built on a singleton pattern, which in my experience makes it just about impossible to know where you are or where you're going.

Is Symfony2 ready for production?

I am in the process of planning a custom web application which will be sold (not SaaS) and so will be required to be installed on different servers. Do you think it would be a bad/good idea to go with Symfony2 or Zend Framework.
I have to choose 1 and can't go with any other framework as I only have extensive knowledge with both of these. Despite my experience with Symfony2, I would still appreciate another opinion.
My main concerns are ease of install on servers and source code protection. Sadly, it would seem ZF already has this going for it in that you don't need 5.3 like Symfony2, and we have Zend Guard.
Any advice is welcome! I am looking to nurture and grow this app and I really want to be sure the first step is the right one.
The Symfony2 download page still says:
Be warned that Symfony 2.0 is not
stable yet; use it with caution
(current version is Beta 1).
So I would wait just a but for Symfony2.
I'm not sure what you mean by source code protection but there is no point in encoding any part of any of the two frameworks since they are both open source (and you should see if their licenses actually do permit that!).
Zend Framework 2 is still in the oven and for the looks of it, Symfony2 will be out of beta way before ZF2. If you can't wait, then use the one that you are most comfortable with. Otherwise, wait for Symfony2 to come out of beta and then wait a little bit more until they iron out it's bugs.
Now, about bundling the framework in your application, you are probably going to need to write an installer of sorts. You could first look at the "sandbox" version of Symfony to see how they did that. It's basically an unzip-it-and-it-works kind of install. No need to set anything up. That could give you some pointers.
Whatever you do, you'll need to write a minimum specs script that users can download and run to check whether their system has everything ready to run your app (check configs, php modules, etc, etc). See SlideShowPro Director for an example of such scripts.
Subjective answer: I'd go with ZF because that's what I know better, but having said that, performance wise I've had better results with Symfony. Apparently ZF2 will have see huge speed improvements.

Upgrading a PHP/MYSQL application?

I'm looking for inputs into how I can manage the upgrade process itself of a homegrown php/mysql application. Meaning, if we have a 'stable' version of our php/mysql application working on our production server, and we now want to upgrade it to the next version that we've worked on - how do we go about doing that elegantly? What practices should I be implementing?
What I was planning to do was just to
Ask the developers to stop
checking in code after all stability
/ functionality tests are done
Take the application offline*** (Q: how should I prevent ppl for logging in / accessing public pages? Best practices for that?) but allow access to developers through a secret login page / url
Log onto the production server and check out the latest version
locally***
Have the developers/testers test their code through the secret access page / url***
After that is done, we restore access to all by removing this secret access page / url, removing the site-under-maintenance page and restoring access to all.
***NOTE: A simple way of doing this would be to rename /myapp/ to /myapp.old/ and put the new application version into /myapp.new/ Developers would access /myapp.new/, test to their satisfaction and then after we're done, we would rename this back to /myapp/ (this is just the basic idea)
This is a huge question, and in many ways it will depend on your specific project. But here are some practices to think about:
Put lots of comments in your code. Things that seem perfectly logical now will be confusing when you go back to make changes in a year or two.
Maintain a development version of the site with its own database. You can test changes to the site before publishing to your production site.
Use a PHP framework (such as CakePHP, CodeIgniter, etc). If you are far along on your project, this may be difficult to do. But it will help you write code in a way that is easy to update, and will include a lot of stable, mature functions that you won't have to write from scratch. Using one of these frameworks (and following its best practices) is probably the best way for a beginner to learn to think about writing modular code that's easy to update. This will also encourage you to develop your database in a way that is consistent with the structure of your site.
Write tests (the framework should help you with this) to programatically check your code for errors.
Use a version control system such as Subversion or Git. This allows you to track changes to the site, and easily roll back changes if/when you realize they are buggy.
Comprehensive unit test coverage would be very helpful, as would small, highly cohesive, low-coupled classes. In addition to the unit tests, good coverage from an integration level would be valuable.

Categories