Make REST calls in PHP

Example of calling GET request
//next example will recieve all messages for specific conversation
$service_url = '[CONV_CODE]/messages&apikey=[API_KEY]';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
    $info = curl_getinfo($curl);
    die('error occured during curl exec. Additioanl info: ' . var_export($info));
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
    die('error occured: ' . $decoded->response->errormessage);
echo 'response ok!';

Continue reading

PHP Requests Library within CodeIgniter

Simple way to use Requests for PHP with Codeigniter.

You may follow these few easy steps.

Step – 1

Unzip latest Requests for PHP zip and copy the contents of the library directory to {codeigniter_directory}/application/third_party/Request-{version} for example you have Requests for PHP 1.6.0 and your CI project is in /usr/sites/www/myproject then copy the files to /usr/sites/www/myproject/application/third_party/Requests-1.6.0.

Continue reading

Dynamically Add Javascript and CSS Files in CodeIgniter Header Page

Those who are developing web projects know that, header pages are always the constant file of their template folder. The classic way of using a header page in small projects are to fill it with constant JavaScript and CSS files along with html tags and use it in inside functions where you need. The problem arise when you start to develop a bigger project where you need to use different JavaScript and CSS files. The bad practice is to load all needed files in the header page, that will also start to appear and load in the pages and sections which we do not need them. This will make the page load slow and will cause conflicts and usage problems.

Continue reading

Logging uncaught exception (redirecting from sysout to logger)

Uncaught exceptions in Java are handled by the System. The JVM usually logs the exception into the System.err and then shuts down. But in case of web applications its different. It logs the printstack trace to server console and then continues. Even though most of the time System.err is redirected to a file system, I wanted a better way of handling it just like any other exception stacktrace. I wanted logger ( you can use log4j too) to handle it, so I it can help maintainers better.
Java gives Thread.UncaughtExceptionHandler to handle any such exceptions. I implemented my own.

Continue reading