Remote Intelephense with Emacs LSP

I have come to rely on Intelephense for any kind of PHP hackery, and this includes when I’m quickly editing a file on my own remote server, or in a vagrant box or what have you. Remote editing is one of the big strengths for me when it comes to using Emacs, and TRAMP has been serving me very well for it, by default so LSP servers don’t “just work”(TM) when accessing a remote file as the local LSP server won’t have access to the files. Luckily lsp-mode already has provisions for it so and will recognize that a file is remote, and startup an LSP server on the target machine if available, but it requires some configuration. For Intelephense this means making sure it is installed on the remote, easily done via NPM, and setting up a remote client configuration somewhere, for me best done as part of initializing lsp-mode.

(use-package lsp-php
  :config
  ;; register remote intelephense
  (lsp-register-client
   (make-lsp-client :new-connection 
                    (lsp-tramp-connection lsp-intelephense-server-command)
                    :activation-fn (lsp-activate-on "php")
                    :priority -1
                    :notification-handlers 
                    (ht ("indexingStarted" #'ignore)
                        ("indexingEnded" #'ignore))
                    :initialization-options 
                    (lambda ()
                      (list :storagePath lsp-intelephense-storage-path
                            :globalStoragePath 
                            lsp-intelephense-global-storage-path
                            :licenceKey lsp-intelephense-licence-key
                            :clearCache lsp-intelephense-clear-cache))
                    :multi-root lsp-intelephense-multi-root
                    :completion-in-comments? t
                    :remote? t
                    :server-id 'iph-remote
                    :synchronize-sections '("intelephense"))))

I am reusing the lsp-intelephense-server-command and most of the other lsp-intelephense variables as they contain the right configuration, and I haven’t had an issue, even so lsp-intelephense-storage-path might need configuration depending on the value and setup, but it has worked for me. Importantly server-id and remote? need to be set for lsp-mode to handle the remote server correctly, but this has worked like a charm for me. Having the same tooling both locally and remote sure is nice!

Setting up Couchbase PHP-SDK with XAMPP on Windows

Getting up and running with PHP on Windows has always been quite easy due to
XAMPP. It provides everything needed
to get started quickly and build something using a default stack available
everywhere. A lot of people get (or got) started this way, including me. But now
that MySQL, PHP, and Apache are setup maybe it’s time to try something new. For
me it’s been a while since I ran a setup like this and so I thought it’s worth
documenting the process.

Getting all the pieces

First of all you’ll need:

  • XAMPP for all your PHP and
    Apache needs, so install at least PHP and Apache
  • Couchbase, remember that you can try
    out the Enterprise version for development for free.
  • Couchbase-PHP-SDK
    XAMPP uses thread safe PHP so make sure you download the correct version
    (either x86 or x64 Thread Safe) for your environment.

Getting everything installed

For Couchbase and XAMPP you basically follow the instructions on the screen to
get it up and running, and make sure you configure Couchbase as well at the end
by visiting the web interface. Now all there is left is
moving the PHP stuff into place, which is probably the most complicated part of
a really easy setup. The zip downloaded from the windows PECL
page
contains 2 dll files,
libcouchbase.dll and php_couchbase.dll which need to be moved in the right
place. First to make php find libcouchbase it’s needs to be present c:apachebinlibcouchbase.dll and to make sure you can also use
php from the command line also copy it to c:xamppphplibcouchbase.dll and
add the XAMPP PHP to your PATH by going to Control Panel -> System and Security
-> Advanced System Settings -> Environment
Variables and edit the PATH
variable by appending c:YOUR XAMPP DIRECTORYphp. And that’s it you are
now ready to use Couchbase in XAMPP, by adding the extension to php.ini, so just add

https://gist.github.com/sideshowcoder/df131b67c173066291c3.js

Try it out!

Create a new PHP file at c:YOUR XAMPP DIRECTORYhtdocscb-test.php containing

https://gist.github.com/sideshowcoder/047d7989ad77e2b955e1.js

and open it in your browser to make apache run
it
you should now see the result in your browser.

cb-test-result

you can also use the command line of course.

cb-test-cmd

The end!

OK so you are now ready to use Couchbase from PHP, and if you need any help and
are in London this week stop by the Couchbase Developer Day as part of Big Data
Week
,
or even if you don’t still you should still stop by.

EDIT

You should also checkout Trond Norbye’s Blog basically describing the same setup.

Give me my $_POST, or a JSON helper for CodeIgniter

In a current Project I’ve been working with a Cappucino frontend and a CodeIgniter Backend. Since Cappucino just loves JSON I decided this is the way to go, sadly PHP doesn’t provide a standard way to interact with a JSON POST but with a little helper this can be solved easily. I made a Gist out of it so it can be improved apon and reused.

https://gist.github.com/1826959.js

Using shell script to deploy automatically

Automatic deployment is essential for any project which is supposed to be worked on and run continuously. Until recently I was using capistrano to do this, but since development seems to have kind of stalled recently I decided to look around for an alternative, which I found in deploy a shell script by TJ Holowaychuk. To check it out I am currently using it to deploy a small Codeignitor project I am working on the side and use to try out new stuff. It really is easy to use and quite flexible due to allowing pre and post deploy hooks as well as automatic tests to check if the deployed version is working, and rollback if it is not. The use with CI is quite simple the only thing todo is to make sure that the right permissions are set which can be easily handled by a post-deploy shell script.

Usage

On the server it creates a simple directory structure with

ENV_ROOT/current
ENV_ROOT/shared
ENV_ROOT/source

in my case for both staging and production. This is done via an initial

deploy [ENV] setup

all following deploys are done by issueing

deploy [ENV]

deploy shell script

Modifications

For some reason some commands were not working for me in Bash ond my Mac so I had to do some small ajustments, I guess it is due to the version of bash I am using being not current maybe. You can find them in my fork

Integrate doctrine 2 in zend 1.11

Just some quick notes on zend and doctrine. Right now I am in the process to rewrite a web application which is based on zend and doctrine, and in the process is ported over to the latest versions of both. Since doctrine does not integrate completely seamless in zend, yet, there is some glue code to be included to make it work. While looking for the right way to do it I came across a video which explains everything nicely. The code which holds everything together is Bisna which is available as part of NOLASnowball. To make it work simply check out the
“doctrine2-managed-crud” branch


$ git clone https://github.com/ralphschindler/NOLASnowball
$ git co doctrine2-managed-crud

and copy Bisna, Symphony, Doctrine from the library folder to your project, also the application.ini file needs to be adjusted to. For a more extensive explanation check out the video mentioned above.