22
Fri, Nov
1 New Articles

TechTip: Running PHP Scripts - Zend Studio

Scripting
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Last month, we talked about Zend Server. This month, the other brother Darryl, Zend Studio, is on tap. Let's see what's up about that.

 

I want to continue my ode to Zend products by taking a look at Zend Studio, the IDE that complements but is separate from Zend Server.

That is, all MAMP and Zend Server provide is the web server part of the equation. We need that web server, because PHP is a server-side language. It doesn't run on your PC in the browser the way HTML or JavaScript does. It needs an actual web server environment to run in.

In order to actually create the script that you run in this web server, we used a text editor. Notepad is a text editor, but there are lots of others. Some are sophisticated and can do code completion or code coloration (so you can more readily identify when things are entered properly) and such. A lot of heavy-duty PHP gods and goddesses use text editors, so there's nothing wrong with that.

But, if you're using Zend Server, then using Zend Studio as an IDE (rather than just using a text editor) is pretty natural. It's more sophisticated than any editor could be, and for a lot of people it is the answer. If only we could figure out what the question is. Yeah, that's a joke. Feel free to laugh…or not.

Getting Zend Studio

Zend Studio does not come bundled with Zend Server. You have to download it separately.

Like Server, Zend Studio is free for one year for IBM i users. With that, you get support and new releases, but after the first free year, you need to buy a subscription if you want that to continue. Costs are about a couple of hundred dollars per year, so it could be worse, and there are numerous plans to choose from. Pricing info is here.

You can download Studio from the Zend website and follow the carefully written instructions so that you don't have (too many) problems. It's not that hard. After all, I did it, so how tough can it be? Just go here and select the platform you're downloading to (Mac, Windows, or Linux). Remember, IBM i is not an option here as we are putting this on your PC, whereas Server could go on the PC or the i.

Something to Know About Zend Studio

I tend to get hung up on little things, so this may not be a big deal to anyone else, but it took me a while to get straight with a couple of things, so I want to point them out to you now in case you're like me.

How Zend Studio Works

Zend Studio is meant to run along with a server, probably Zend Server, but it doesn't have to be. You could use it with MAMP, for example.

The point is, Studio does not have a built-in web server, and remember, since PHP is a server-side language, you need a web server to make it work. Studio is primarily an IDE, and the server you're using will be separate from it.

However, it does have the ability, when you write a script, to debug or just run that script in Zend Studio and see what the output isthat is, even though you don't have a web server up and running at the moment. The output doesn't appear on a browser window, but rather on a window within Studio. This allows you to do your development and unit testing just in Studio without bringing a formal server into the picture.

What Zend Studio Looks Like

I have to admit, when I first looked at it, I found Zend Studio confusing. Actually, I still find it confusing at times, but I'm honestly not sure what I would do about it if I were in charge of changing it.

Studio consists of multiple (many) windows that each show a particular type of information. They don't have to all be open at the same time (and aren't), but generally enough are open to make it look busy. And there seems to be a certain tendency to change the names of windows or the spot from which you can access them from release to release.

And that may just be me. Seriously. I don't want to scare you away even before you begin, but at the same time, I don't want you to freak the first time you see it. Word to the wise (or whatever): if Studio looks overwhelming the first time you see it, don't panic. You're not the first person to feel that way, and if you just take a deep breath and focus just on the things I will show you, you'll be able to use it pretty quickly. You can always add in more detail later as you become familiar with it.  

Opening Studio

At this point, I'm going to assume you have Studio loaded on your PC. Go ahead and click on the icon to start 'er up.

There may be some initial windows that come up. It's been a while since I installed my version, and I don't remember. Nor am I about to do it again just for you. Sheesh. The nerve of some people.

One window you will be faced with asks you to select a workspace. Since Studio is a PC product, it needs a workspace to run in. You may actually have several, so it lets you choose which one you want. A default workspace is created when you do the download, but you can easily create others if you feel so moved. This window allows you to select one or set one as a default so that the window no longer appears.

When the main window opens up, you'll see tabs at the top of each sub-window telling you what each does (Figure 1 below), and most of the windows are capable of showing you multiple things. Exactly what windows you have open will depend on your particular configuration (that is, what you had open the last time you used Studio). Naturally, the entire window can be resized, and each individual sub-window can be sized to make it larger or smaller, but those are the only two options available (larger or smaller). At this point, I would take a minute to look over the sub-windows and the tab names. Remember, just breathe.

 030416Shirey1

Figure 1: This is the initial Zend Studio page.

Creating a PHP Project

How do we enter a PHP script? First, make sure the PHP s-w (sub-window) is showing. If it isn't, go up to the top and look at the icon line.

030416Shirey2

Figure 2: This ribbon line opens PHP Explorer.

On the right side of this line, you'll see PHP or PHP Explorer (I've seen it both ways). Click on that. If you're using an earlier version (like 12.5), you might have to go up to Windows on the menu line and select Show View or Perspectives to find PHP. Once you find it, click on it.

After a moment, the sub-windows will magically reorder themselves, and one with a PHP Explorer tab will appear. In it will be a list of the projects you have already defined. If you're just starting, then this will be empty.

030416Shirey3

Figure 3: The PHP Explorer Window shows existing projects.

In Studio, you don't create folders or directories in which to store and organize the scripts you create; you create projects. So the first thing we will do is have you create a project. You can't create even a Hello World script until you create a project. Well, you could (as you can see, I have but that was early on, and I know now that it was wrong), but you shouldn't. Put everything in a project. To create a project, go back up to the menu line, and do this: File > New > Local PHP Project.

As you can see from the New list, you can create a large number of objects in Studio. We'll look at almost none of these, but you can experiment on your own. Anyway, the result will be a pop-up window in which you will define your project.

030416Shirey4

Figure 4: Create a project window.

All I'm going to do here is type in "TechTip," the name I'm assigning to this project, and I may change the version from PHP 5.6 to PHP 7. Up to you. When I start keying in the Project Name, the Next and Finish buttons will un-gray. When I'm ready to continue, I could hit Next, which would take me to a list of extra PHP and other software libraries that I could attach to this project to make their stuff available for these scripts. I'm not going to do that this time, however, so I just hit Finish.

Note that there are other things I can do here. First, if I have several web servers on my system, I can choose the particular one I want associated with this application. I can also decide if I want the app set up in a Zend Framework format. Finally, I can make it work more closely with Composer. Using Composer to manage library and application dependencies is very common in the PHP world, so working it directly into your application is a big plus.

Anyway, as soon as you hit Finish, Studio will update the PHP Explorer window, and you'll see your new project out there. Exciting. But wait. There's a triangle next to it, the international symbol for "open me up and see what's inside." Inside? We haven't created anything in that project yet. “Just what in the Wide World of Sports is a goin' on here?” If you open it up by clicking on the triangle, you'll see three things inside that project, things that Studio has created for you. And if you then click on the triangle by the Include Path or Language Library entries, you'll see even more stuff.

Take another deep breathe. This is not proof of demonic possession. Just relax and focus on your breathing until it is slow and regular. What happens here is Studio is somewhat framework- oriented, and frameworks like to create things that they think you'll use later. Mostly, just ignore this stuff for now. We may use it later, like in a year or two, but for now just know it's there and you don't need to fuss with it.

The one file that you might use is the index.php. Studio has created this automatically. It's a blank PHP file with the name defaulting to the default name for a web home page. All that's in this file is the starting PHP delimiter <?php. But you could use this to start your script in. In our case, we will go thru the process of creating our own PHP file. And remember, when we say "PHP file," we're not talking about a data file but rather a source file where we'll enter our script.

Creating a PHP File

Let's suppose that we don't want to use the index.php that was created for us but instead want to create our own script file. To do this, go back up to the menu line: File > New > PHP File. Suddenly, a window will appear.

030416Shirey5

Figure 5: Create a PHP file in a project window.

You can click on the project you want this file to be in and then enter the name you want assigned to this file where it says File Name about halfway down. I'm not covering this now, but the Advanced button opens up fields where you can tie this file to a regular data file in your file system. Once you start keying on this screen, the Next and Finish buttons un-gray. I'm going to use the name File1.php.

The Next button takes you to a list of PHP templates that you can assign to this file. Choosing a particular template will cause some standardized code to be automatically thrown in the file, which saves you coding time. Among the choices are models for controllers, action helpers, HTML front ends, etc.

Hitting Finish just gets you out of there. It creates the file and then opens it in the blank window immediately to the right of the PHP Explorer window you're working on.

030416Shirey6

Figure 6: PHP Explorer shows the project and PHP file.

As you can see, there's not much in File1.php because we didn't select one of the templates, but that's fine with me. What I want you to do at home is add the following code. Be sure you get all the quotes and double quotes correct.

echo 'I"m a total butt wad.';

?>

Sorry, but I think "Hello World" is so day before last Thursday, and I wanted a shout-out to long-haired Penny and The Big Bang Theory. Save this using File > Save. Don't close it; just save.

030416Shirey7

Figure 7: See PHP Explorer and the file code when you select a specific file.

Running PHP Script in Studio

Now, to run this in Zend Studio and see if it works, go to the menu line and select Run > Run As > PHP CLI Application.

I haven't had good success with Run > Run, so I suggest using Run As. If there are no options when you click on Run As, click Run Configurations below it and then just press Enter. Then go back to Run As and there should be three options there, one of which is the CLI (Command Line Interface) option.

Now, go to the sub-window along the bottom of the screen and select the Browser Output tab.

030416Shirey8

Figure 8: See PHP Explorer and File1.php when you enter code.

See, it worked. Now this is just a test. We're not running this in the Zend Server, and in fact you don't even need the Server up to develop and test PHP code.

So, Are We Done?

Fine, we're done. At least, I'll let you go at this point. But there's a lot more to do. This script ran perfectly, which is surprising because I wrote it. That ain't gonna happen twice in a row, cowboy. So stay tuned

David Shirey

David Shirey is president of Shirey Consulting Services, providing technical and business consulting services for the IBM i world. Among the services provided are IBM i technical support, including application design and programming services, ERP installation and support, and EDI setup and maintenance. With experience in a wide range of industries (food and beverage to electronics to hard manufacturing to drugs--the legal kind--to medical devices to fulfillment houses) and a wide range of business sizes served (from very large, like Fresh Express, to much smaller, like Labconco), SCS has the knowledge and experience to assist with your technical or business issues. You may contact Dave by email at This email address is being protected from spambots. You need JavaScript enabled to view it. or by phone at (616) 304-2466.


MC Press books written by David Shirey available now on the MC Press Bookstore.

21st Century RPG: /Free, ILE, and MVC 21st Century RPG: /Free, ILE, and MVC
Boost your productivity, modernize your applications, and upgrade your skills with these powerful coding methods.
List Price $69.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: