Archive for February, 2012

Manually Installing Php on any system

This section contains instructions for manually installing and configuring PHP on Microsoft Windows. For the instructions on how to use PHP installer to setup and configure PHP and a web server on Windows refer to Windows Installer (PHP 5.2 and later).

Selecting and downloading the PHP distribution package

Download the PHP zip binary distribution from » PHP for Windows: Binaries and Sources. There are several different versions of the zip package – chose the version that is suitable for the web server being used:

If PHP is used with IIS then choose PHP 5.3 VC9 Non Thread Safe or PHP 5.2 VC6 Non Thread Safe;

If PHP is used with IIS7 or greater and PHP 5.3+, then the VC9 binaries of PHP should be used.

If PHP is used with Apache 1 or Apache 2 then choose PHP 5.3 VC6 or PHP 5.2 VC6.

Note:

VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the » Microsoft 2008 C++ Runtime (x86) or the » Microsoft 2008 C++ Runtime (x64) installed.

The PHP package structure and content

Unpack the content of the zip archive into a directory of your choice, for example C:\PHP\. The directory and file structure extracted from the zip will look as below:

Example #1 PHP 5 package structure

c:\php
|
+–dev
| |
| |-php5ts.lib — php5.lib in non thread safe version
|
+–ext — extension DLLs for PHP
| |
| |-php_bz2.dll
| |
| |-php_cpdf.dll
| |
| |-…
|
+–extras — empty
|
+–pear — initial copy of PEAR
|
|
|-go-pear.bat — PEAR setup script
|
|-…
|
|-php-cgi.exe — CGI executable
|
|-php-win.exe — executes scripts without an opened command prompt
|
|-php.exe — Command line PHP executable (CLI)
|
|-…
|
|-php.ini-development — default php.ini settings
|
|-php.ini-production — recommended php.ini settings
|
|-php5apache2_2.dll — does not exist in non thread safe version
|
|-php5apache2_2_filter.dll — does not exist in non thread safe version
|
|-…
|
|-php5ts.dll — core PHP DLL ( php5.dll in non thread safe version)
|
|-…

Below is the list of the modules and executables included in the PHP zip distribution:

go-pear.bat – the PEAR setup script. Refer to » Installation (PEAR) for more details.

php-cgi.exe – CGI executable that can be used when running PHP on IIS via CGI or FastCGI.

php-win.exe – the PHP executable for executing PHP scripts without using a command line window (for example PHP applications that use Windows GUI).

php.exe – the PHP executable for executing PHP scripts within a command line interface (CLI).

php5apache2_2.dll – Apache 2.2.X module.

php5apache2_2_filter.dll – Apache 2.2.X filter.

Changing the php.ini file

After the php package content has been extracted, copy the php.ini-production into php.ini in the same folder. If necessary, it is also possible to place the php.ini into any other location of your choice but that will require additional configuration steps as described in PHP Configuration.

The php.ini file tells PHP how to configure itself, and how to work with the environment that it runs in. Here are a number of settings for the php.ini file that help PHP work better with Windows. Some of these are optional. There are many other directives that may be relevant to your environment – refer to the list of php.ini directives for more information.

Required directives:

extension_dir = – The extension_dir needs to point to the directory where PHP extensions files are stored. The path can be absolute (i.e. “C:\PHP\ext”) or relative (i.e. “.\ext”). Extensions that are listed lower in the php.ini file need to be located in the extension_dir.

extension = xxxxx.dll – For each extension you wish to enable, you need a corresponding “extension=” directive that tells PHP which extensions in the extension_dir to load at startup time.

log_errors = On – PHP has an error logging facility that can be used to send errors to a file, or to a service (i.e. syslog) and works in conjunction with the error_log directive below. When running under IIS, the log_errors should be enabled, with a valid error_log.

error_log = – The error_log needs to specify the absolute, or relative path to the file where PHP errors should be logged. This file needs to be writable for the web server. The most common places for this file are in various TEMP directories, for example “C:\inetpub\temp\php-errors.log”.

cgi.force_redirect = 0 – This directive is required for running under IIS. It is a directory security facility required by many other web servers. However, enabling it under IIS will cause the PHP engine to fail on Windows.

cgi.fix_pathinfo = 1 – This lets PHP access real path info following the CGI Spec. The IIS FastCGI implementation needs this set.

fastcgi.impersonate = 1 – FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.

fastcgi.logging = 0 – FastCGI logging should be disabled on IIS. If it is left enabled, then any messages of any class are treated by FastCGI as error conditions which will cause IIS to generate an HTTP 500 exception.

Optional directives

max_execution_time = ## – This directive tells PHP the maximum amount of time that it can spend executing any given script. The default for this is 30 seconds. Increase the value of this directive if PHP application take long time to execute.

memory_limit = ###M – The amount of memory available for the PHP process, in Megabytes. The default is 128, which is fine for most PHP applications. Some of the more complex ones might need more.

display_errors = Off – This directive tells PHP whether to include any error messages in the stream that it returns to the Web server. If this is set to “On”, then PHP will send whichever classes of errors that you define with the error_reporting directive back to web server as part of the error stream. For security reasons it is recommended to set it to “Off” on production servers in order not to reveal any security sensitive information that is often included in the error messages.

open_basedir = , e.g. openbasedir=”C:\inetpub\wwwroot;C:\inetpub\temp”. This directive specified the directory paths where PHP is allowed to perform file system operations. Any file operation outside of the specified paths will result in an error. This directive is especially useful for locking down the PHP installation in shared hosting environments to prevent PHP scripts from accessing any files outside of the web site’s root directory.

upload_max_filesize = ###M and post_max_size = ###M – The maximum allowed size of an uploaded file and post data respectively. The values of these directives should be increased if PHP applications need to perform large uploads, such as for example photos or video files.

PHP is now setup on your system. The next step is to choose a web server, and enable it to run PHP. Choose a web server from the table of contents.

In addition to running PHP via a web server, PHP can run from the command line just like a .BAT script. See Command Line PHP on Microsoft Windows for further details.

Advertisements

How to call a PHP Script from ASP.NET C# and View Its response?

Hi guys,
I was wondering on net abt , how to call a PHP Script from ASP.NET C#, then found a simple solution.
Actually, Its nothing but calling any other ASP.NET C# file.
The script is as follow:
Basically I wanted to send User Id and Account ID and then process the table:

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(“http://rover.geodesic.net/wcv1/php/ProcessTrans.php?userid=” + item.Value + “&accountid=” + item.Key + “&type=stock”);

// Set the ‘Timeout’ property in Milliseconds.
myRequest.Timeout = 600000;//10 mintutes
myRequest.Method = “GET”;
HttpWebResponse newStream = (HttpWebResponse)myRequest.GetResponse();

if ((newStream.ContentLength > 0))
{
System.IO.StreamReader str = new System.IO.StreamReader(newStream.GetResponseStream());
Response.Write(str.ReadToEnd());
if (str != null) str.Close();
}

The small changes I did was, I multi threaded the process, as i was taking more time to execute the PHP page “ProcessTrans.php”;
In above example, Data has been sent in “GET”
If you want to Post Data to remote Web Page using HttpWebRequest :

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(“http://rover.geodesic.net/wcv1/php/ProcessTrans.php?userid=” + item.Value + “&accountid=” + item.Key + “&type=stock”);
request.Method = “POST”;
request.ContentLength = data.Length;
request.ContentType = “application/x-www-form-urlencoded”;
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
response.Close();
Response.Write(tmp);
}

It might not work if the site you’re trying to stream is protected by authentication. If it’s Windows/NTLM Authentication and your account has privileges on the site, try using:
request.Credentials = CredentialCache.DefaultCredentials;
after the create request.

Ref: http://www.worldofasp.net/tut/WebRequest/Working_with_HttpWebRequest_and_HttpWebResponse_in_ASPNET_114.aspx

regards,

Ruby in Steel on Visual Studio 2008

The only professional Ruby development tool for Visual Studio, Ruby In Steel Developer 2 has powerful analytical IntelliSense, the fast ‘Cylon’ debugger, syntax-sensitive editing and comprehensive development support for Ruby and Rails.

– Go to: Ruby In Steel Download Page

Here we provide a brief overview of just a few of the major features of Ruby In Steel…
Debugging

Ruby In Steel’s ultra-fast ‘Cylon’ debugger provides…

– Speed

The ultra-fast ‘Cylon’ debugger

Ruby and Rails debugging is notoriously slow. Not any longer. Ruby In Steel’s Cylon debugger blazes through your code.

– Breakpoints and Tracing

Step through your code

Step into/step-out/step-over code in Ruby and Rails applications.

– Hover and Drill-down

Drill-down debugging

Drill-down debugging lets you look inside objects and expand arrays and hashes in the docked debugging windows, in the code editor or even right inside the interactive Ruby console!

Docked debug windows

– Conditional Breakpoints

Add conditions in Ruby code

Break when a condition (a test of one or more values) is met.

Other debugging features:
– Tracepoints
– JRuby Debugger
– Break on exception
– Break on hitcount
– Run macro on break

The debugger is supported by a range of tools and windows including:
– Watch
– Locals
– Autos
– Quick Watch
– Breakpoints
– Call Stack.
Editing

Ruby In Steel provides extensive syntax-aware editing for Ruby and Rails.

– Code Coloring and Code Folding

Code coloring and folding

The code editors provide customizable coloring – even for Ruby code embedded into Rails Erb templates. Code folding operates on classes, modules, methods, if blocks and many other constructs – including user-defined collapsible regions…

– Bracket and Keyword/end Matching

Keyword..end matching

Opening and closing brackets are highlighted. A keyboard shortcut lets you move you cursor between brackets or Ruby keyword/end pairs such as class…end and def..end.

Ruby In Steel also has…

Snippets with ‘edit points’

– Snippets that auto-generate code blocks

Ruby and ERb Snippet editor

– A Snippet editor to let you create your own snippets without coding
– Smart or Block indenting to auto-align align your code
– Automatic code formatting (a selected block or an entire document)
Plus all the editing features you would expect such as multi-level undo/redo, bookmarks, split-window editing and user definable macros.
IntelliSense

Ruby In Steel offers unparalleled analytical code completion and navigation tools for Ruby.

– Fast Code Completion Analyzes Code As It Is Written

Drop-down lists provide relevant and accurate information on the methods that are available to objects and classes (both those in the Ruby and Rails libraries and those that you write yourself).

‘Local scope’ (Common) code completion

Dual-page completion lists let you show class-specific detail, for clarity (see above) or the members of the class and all its ancestors, for completeness (see below).

Broader scope (All) code completion

Code completion is automatically triggered by a dot after an identifier and by the double-colon :: scope resolution operator. Completion lists may also be triggered by CTRL-Space. The IntelliSense engine analyzes code as it is written and updates completion lists as appropriate. You may optionally tailor completion lists by specifically omitting elements such as ancestor class methods, global variables and keywords. Notice that embedded (RDOC) documentation for members is shown in a tooltip. You can also hover over classes and methods in the editor to view RDOC.

– Tooltips and Parameter Completion

Parameter hints

Enter an opening bracket after a method name to see a highlighted hint showing parameters and their types.

Extra parameter information can be added via ‘type assertions’

In cases where classes cannot be inferred, add ‘type assertion’ comments for extra IntelliSense.

Tooltip hint for a variable

Hover over any object to see its fully-qualified (including ‘nested modules’) class name.

– Speed Unlike some other Ruby editors, the Ruby In Steel code completion is fast!
Ruby On Rails Tools

In addition to the Visual Rails Workbench, Ruby In Steel has deep support for Ruby On Rails Development

The Rake and Generate tools

It has project start-up wizards and (optionally) docked, tabbed and floating tool windows and dialogs such as:
– Generators
– Rake Tasks
– Gem Run
Tools and Wizards

Docked or floating consoles

– Fully integrated Ruby, Rails, Script and IRB consoles

Context-sensitive online documentation

– RDOC window shows formatted documentation when you hover over an object identifier in the editor

The Ruby Explorer

– The Ruby Explorer lets you navigate the class library – even into documentation extracted from C-source files

Context-sensitive Navigation Bars

– Drop-down Navigation Bars over the editor for fast code navigation

Manage projects in the Solution Explorer

Ruby In Steel projects are managed from the Visual Studio Solution Explorer. You can simply create, import or convert Ruby and Rails projects as well as add, move and delete files and folders. Ruby In Steel is fully configurable (colors, tab and formatting options etc.).

For more details, refer to The Feature List.

Minimum Requirements: Visual Studio 2010 Standard Edition or above; alternatively, use the Ruby In Steel ’All-in-one installer’ to install a free Ruby-language copy of Visual Studio 2010.

Link : Ruby in Steel

Ruby In Steel -> Visual Studio 2008 Edition

Free VS 2008 upgrade
by Huw Collingbourne, Employee @ SapphireSteel Software

Quite a few of our customers are already using the beta version of our Visual Studio 2008 edition of Ruby In Steel. Now that Microsoft has shipped the final release of VS 2008, we are going through a last round of testing prior to launching the first official VS 2008 edition of Ruby In Steel. That should be along in a few weeks.

Visual Studio 2008 has a number of new and useful features – such as the ability to make completion lists transparent when you press the Control key – very useful if you want to check the code under the list.

Over the past week or so we have had a number of enquiries from potential purchasers wanting to know if we will be charging extra for our VS 2008 edition. The answer is: No.

If you buy Ruby In Steel Developer today you will be able to upgrade your software to all subsequent editions of the version 1.x product at no additional cost. It makes no difference whether you want to carry on using the VS 2005 edition or if you prefer to switch to the VS 2008 edition. We’ll issue updates to both editions and all of the updates will be free to registered users. In fact, if you like, you may download and install both the VS 2005 and the VS 2008 updates. According to the terms of our license:

“If you wish to install the software onto more than one computer, you may do so. If a second person wishes to use the software, however, then you need to buy a second license.”

As we’ve previously stated, the price of Ruby In Steel will increase with the next major release (1.2) from $199 to $249. However, anyone who buys at the current lower price will have all the upgrades – free of charge – to all VS 2005 / 2008 editions throughout the lifetime of Ruby In Steel 1.x.

We shall shortly release a version of Ruby In Steel 2008 which, to the best of our knowledge, will be functionally equivalent to our VS 2005 product. However, until we are sure that there are no major incompatibilities with VS 2008, this version will be released as a beta. Our final release will follow after a further period of testing.

VisualStudio as my IronPython editor

The following steps are what I did to get Visual Studio ready as my IronPython (and IronRuby) editor.

* Install the latest internal dogfood build of Visual Studio 2008.
o you may use Visual Studio 2005 or download the VS 2008 public beta2;
* Download and install ASP.NET futures release (July 2007). This will give me the nice syntax coloring and (well… limited) intellisense for python code.
o you may download VSSDK 2008 CTP, and build the IronPython integration sample, which will give you the similar editing experience;
* Download the attached add-in binary zip (poorly named as DlrToolsAddin); for my Vista box, I extract them under “%USERPROFILE%\Documents\Visual Studio 2008\Addins”. I wrote this add-in basically to allow me to run the script inside the Visual Studio, and show the output in the output window.
o if you consider using it for VS 2005, you will need put it in “Visual Studio 2005\Addins”.

Say, I am trying the example in my previous post, I create a new C# file (sample.cs) without creating solution/project, I can press Ctrl+1 (or the first button in the DlrTools toobar) to get it compiled to sample.dll in the local directory. You see the compile result at the bottom output window. Then I create a python file (method.py) in the same directory, type in some code (shown in color). Again, I can press Ctrl+1, the result are shown in the output window. I do not need leave VS and run these files in the cmd.exe window.

Sometimes I want to run the same code with different tools (for example, to check IronPython compatibility, I often run the same .py file against C-Python 2.5 too). That is the first combo box comes to play.

The second combo box is to set the working directory: “.” means the current directory where the active file lives, “..” for the parent directory of the current file, or you may use the absolute path. Such support is needed to run C-Python regression tests. (For the add-in implementation side, I feel what I really want is a combo box of type vsCommandControlTypeDynamicCombo, which seems not available for add-in development).

The delete button is to remove your tool choice for those files you pressed “Run Script”. By clicking the last button, an XML file (specifying which tools for which file extension) is opened so you may change it. You must update it with your tool paths, since the default setting is suited for myself.

You may also run part of the file by selecting those lines first (A temporary file is created and will be deleted after VS shutdown).

One bad thing I noticed of this add-in is that sometimes I press the “run script” button to start debugging, both icons have similar shapes.

To uninstall it, delete DlrToolsAddin.* files under “Addins”; and then run once “devenv.exe /resetaddin DlrToolsAddin.Connect”.

The source code (VS2008 project) is also attached. Disclaimer: THE CODE IS PROVIDED “AS IS”, WITH NO WARRANTIES INTENDED OR IMPLIED. USE AT YOUR OWN RISK. Hope you like Visual Studio as your IronPython editor.

Download Source Code Attached

Converting your ASP.NET MVC 3 Compiled website to JIT App_Code website

Working with MVC can be a pain when you want to make simple changes like adding a web page. You must open up a solution in Visual Studio, modify code then compile, then copy your files to your server. This is too many steps for web programming as web programming is supposed to be light weight and fast.

Working with the App_Code folder allows you to make your changes rather quickly and does not require Visual Studio to compile.

In order to do this here are the steps for a typical ASP.NET MVC 3 project:

Open up as a website instead of project in visual studio or web express
Move the Controllers and Models folders into the App_Code folder. Basically this is taking class files and moving them to App_Code so other class files apply as well if on another MVC project like Nop Commerce etc.
Modify the global.ashx file to require no code behind. You do this by taking the contents of the code behind’s class file and copy paste into a runat server on the global.asax directly. Then remove the code behind references and inheritance.
In the bin directory remove the project’s DLL reference but make sure to keep the MVC Dll from Microsoft.
Try it out. This should work like a charm. I typically do this for the new MVC 3 Nop Commerce because I want to be able to modify things very easily and quickly without having to go through builds.

that’s all what we wanted to do ?

ASP.NET: Use VB.NET and C# within the App_Code folder

When I was creating my new blog site, I choose to write it in C#. I had a problem with the App_Code folder because I had some code in VB.NET code and some C# code I needed to put in there. I didn’t want to rewrite my VB.NET code in the App_Code folder just so I could write the rest of the code for the site in C#.
Luckily, the ASP.NET Team had already thought about just this kind of circumstance. They implemented a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn’t have to spend a couple hours converting code from VB.NET to C#!
The below works with ASP.NET 2.0 and later.
Even if you don’t use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.
Step 1: Add the following Sample lines to the web.config in the form of tags.

configuration
    system.web
        compilation
            codeSubDirectories
                add directoryName="VB_Code"/
                add directoryName="CS_Code"/
            /codeSubDirectories
        /compilation
    /system.web
/configuration

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:

App_Code
/App_Code/VB_Code
/App_Code/CS_Code
App_Code

Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.

%d bloggers like this: