Category Archives: PHP on IBM i

Whats going to change when I update PHP on IBM i. PHPinfo is a clue

e Here’s a great little script to see whats going to change when you update PHP on IBM i.  It compares the phpinfo from your production site to your new instance of PHP.  This way you can scroll down and take note of specific differences to PHP.  This isn’t all the changes so there’s more to check but can get you pretty far.

 

https://github.com/brettalton/phpinfo-compare

There is an issue with library lists if your using the PDO_IBM driver.

https://bugs.php.net/bug.php?id=73785

Disable Z-Ray on PHP on IBM i
Edit the file /usr/local/zendphp7/etc/conf.d/zray.ini and change zray.enable=1 to zray.enable=0

; Enable Z-Ray
; zray.enable=1
zray.enable=0

Cross-Site Request Forgery (CSRF) Prevention in PHP

Below is an example of how to prevent cross-site request forgery in PHP. Basically you create a form token tied to the user’s session. When the form is submitted we verify that they have a token and that its the token we issued to the user. If it’s not we don’t process the form and echo out an error message.

Compiling PHP extensions on IBM i / PASE/ AIX

This is post for Andy Youens and anyone looking to compile PHP Extensions on IBM i.  The first thing i would do is get GCC on the IBM i by following Tony’s guide here: http://yips.idevcloud.com/wiki/index.php/PASE/GCC .  GCC is the compiler system that can take a PHP extension  source code, which are written in C, and compile it into an .SO file that can be added via PHP.ini.  In Andy’s case he want’s xdebug and you can get the latest source code here: http://xdebug.org/files/xdebug-2.3.3.tgz . Or find other versions here: http://xdebug.org/download.php .

Compile Script

Why can’t we just use any old binary? 

The source code has to be compiled to the processor and the operating system you’re running it on.  In the case of IBM i , the PASE environment is basically AIX (IBM’s flavor of UNIX) and it runs on IBM’s Power processor.

Binary compiled for PHP 7.1

https://github.com/phpdave/DataDump/raw/master/xdebug.so

 Further reading if you need more information to get strarted:

http://files.zend.com/help/Zend-Server-5.6-Cluster-Manager/content/compiling_php_extensions.htm

 

Who is Rogue Wave Software?

Well that’s the first question that came to my head when i found they were going to acquire Zend.  Below are some links to dive deeper into understanding what they do and offer.  It looks like they are a real good fit for PHP’s future and High-Performance computing.

Website: http://www.roguewave.com/

Wiki: https://en.wikipedia.org/wiki/Rogue_Wave_Software

Crunchbase: https://www.crunchbase.com/organization/rogue-wave-software#/entity

Andi Guttman’s Linkedin message: https://www.linkedin.com/pulse/big-news-enterprise-php-andi-gutmans

Acquisitions

Klockwork – tool helps “developers create more secure and reliable software by analysing source code on-the-fly, simplifying peer code reviews, and extending the life of complex software.” – https://en.wikipedia.org/wiki/Klocwork
IBM’s ILOG Visualization for C++ Productshttp://www.roguewave.com/company/news/2012/rogue-wave-software-acquires-ilog-visualization
Acumem – “performance tuning tools for single- and multi-threaded applications”  – http://www.theregister.co.uk/2010/10/04/rogue_wave_acumem/
TotalView Debugger – insights into debugging high-performance computing (HPC) and supercomputing applications. – http://www.roguewave.com/products-services/totalview
Visual Numerics: advanced analytics software

Zend Acquisition PR

Geek Time’s Article

Check to see if Selenium Server is already running in PHP via Windows command line ( or any java jar file)

The script below will find out if the Selenium Server (java jar file) is already running in windows.  It uses the Windows Management Instrumentation Command-line (wmic) to look at the processes that are running as “java.exe” and gets the command line that started them.  The php script than Iterates through the command line output and looks for  “selenium-server-standalone”.

If you’re not familiar with Selenium you can learn how to use it with PHP here!

Automating Browser Testing with PHP and Selenium

Automated Browser Testing via PHP using Selenium and FB PHP-Webdriver

Automating your browser testing is very easy with using PHP and Selenium.  Below is a diagram of how it all works and the steps on how to achieve controlling your Browser with PHP!

Automating Browser Testing with PHP and Selenium

Automating Browser Testing with PHP and Selenium

Steps to install the basic components

  1. Install PHP on your machine download the PHP executable and set its path up in your environment (not sure how to do that?).
  2. Install Composer which will be used to download the source code for the facebook web driver
  3. Download the Selenium Standalone Server here http://www.seleniumhq.org/download/ (Direct link: selenium-server-standalone-2.53.1.jar)
  4. Run the selenium server by double clicking the jar file or invoking it from the command line..  You could also run this in your php script if you put the jar file in the same directory as the php script: exec(“java -jar “.__DIR__.”\selenium-server-standalone-2.53.1.jar”);
  5. Create a composer.json file https://gist.github.com/phpdave/580e5666c1d78d12e66e
  6. Run composer install using the composer.json file – This will download the facebook web driver
  7. Create an example PHP script on your computer.  https://github.com/facebook/php-webdriver/blob/community/example.php
  8. Run the script on the command line C:\myscripts\> php example.php
  9. This should start your browser up and start running the example script code.  You could then use the web driver to screen scrape, enter in various input and take various actions that are needed to test your application out.  You’ll also have the power of PHP to do various things such as save the results of your test to a file and all this is done in PHP!  So you don’t have to learn another language.  You’ll also want to get comfortable with firefox’s developers tools so you can inspect an element and get a unique selector for that element so you know how to interact with that element.

Note:

  • Supported Platforms: Windows, OSX, Linux.  Not supported on the IBMi.  This makes sense since browsers run on a users machine not on the i.  Therefore to automate you may have to setup a Linux VM on a server and have it called to test.  Or you can run the code on your local machine http://www.seleniumhq.org/about/platforms.jsp

Referencee
www.seleniumhq.org/download/

Adding PHP formatter to Selenium IDE firefox plugin to allow copying and pasting commands in PHP format

  1. Install the plugin here: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-php-formatters/
  2. In Selenium IDE go to Options->Clipboard Formatting-> PHP (PHPUnit)

This will give you output like this:

$this->open("/Page1/");
$this->type("name=field2", "99999");
$this->click("name=Submit");

which you’ll need to modify into this format if your using the PHP FB webdriver:

$driver->get("/Page1/");
$driver->findElement(WebDriverBy::name('field2'))->sendKeys("99999");
$driver->findElement(WebDriverBy::name('submit'))->click();

Adding a user extension to selenium IDE to add a new function

  1. Modify the user-extension.js that the selenium ide is using and add a function like this that will do an random email:
Selenium.prototype.doTypeRandomEmail = function(locator) {
    /**
    * Sets the value of an input field to a random email id,
    * as though you typed it in.
    *
    * @param locator an <a href="#locators">element locator</a>
    */

    // All locator-strategies are automatically handled by "findElement"
    var element = this.page().findElement(locator);

    /* The following block generates a random email string */
    var allowedChars = "abcdefghiklmnopqrstuvwxyz";
    var stringLength = 8;
    var randomstring = '';

    for (var i=0; i<stringLength; i++) {
        var rnum = Math.floor(Math.random() * allowedChars.length);
        randomstring += allowedChars.substring(rnum,rnum+1);
    }

    // Append a domain name
    randomstring += "@example.com"

    // Replace the element text with the new text
    this.browserbot.replaceText(element, randomstring);
};
  1. Then you can just call the function like this:
$this->typeRandomEmail("id=email");

Setting it up on an Amazon Linux EC2 instance

Follow this example to setup PHP on EC2 if you don’t already have a linux box to play with

Open the ports 7055 and 4444 on your EC2 server instance’s security group inbound rules

SSH into your Linux box run:

References: https://lambda-linux.io/blog/2015/01/28/announcing-firefox-browser-support-for-amazon-linux/