postgres on docker

Accessing Docker Postgres from host application

Accessing Docker Postgres in the host application

Accessing docker postgres is was easier with right commands. Docker has been a life saver for most of us – no doubt on that. We can do any kind of software interaction from host machine or from other docker container with bliss.

Once you have the docker postgres up and running, access docker postgres and use it for multiple of your projects. Here I will show how to access docker postgres from host machine. That is the same thing as any other app to access it as well.
Continue reading Accessing Docker Postgres from host application

facebook auto post using php

facebook page post from PHP

How to autopost to facebook page using php

Facebook auto post using php, hmm.., I have a post on this topic a while ago, this one.

This post answers your questions of how to post to facebook page using php.

Though some of the initial steps do still hold, that is no more the case today. In order to combat the fake news and other improper usage of the platform, facebook has come up with different approach.
Continue reading facebook page post from PHP

facebook social marketing

Add batch/multiple posts to Facebook Page – Graph API

facebook graph API batch request usage

If you have or managing any facebook page, chances are you might be using faebook’s graph API. It comes with lots of flavors of languages like Java, PHP, Javascript.

Ok you know about that, this post is not about that. If you want to see how to make a post to facebook through graph API, look at this post https://gullele.com/using-facebook-api-post-articles-php/

This post is about making multiple posts to Facebook page.

Why would I need batch requests

Imagine you have 20 blog articles you want to post to facebook. If you are not using batch, then it means you are sending 20 post requests to facebook. And as you can imaging it is easy to hit the limit easily. Facebook will stop you from bombarding their site.

When you are using batch, you have only one request, holding all 20 posts. Yup, that is it. One request vs 20. Now you know why you have to use that.

How to send multiple blog posts or other posts to Facebook page at once

If you follow the above link I referenced, you will have an idea on how single post is doing. I will just continue on that example class and will add just one more method to handle batch request.

The main idea is, each blog or whatever post has to be an object of Request. And you will send all those requests wrapped in one and send it.


	/**
	 * Send batch request to FB than a single one
	 * @param $post_data
	 */
	private function batchPost(array $post_data, $token)
	{
		/*
		 * In the case of the batch request, each has to be an object of request. And all those can be 
		 * send as one big request.
		 */
		$batch_response = [];
		$requests = [];
		foreach ($post_data as $id => $data) {
			$requests[$id] = $this->facebook->request('POST', '/me/feed', $data);
		}

		$batch_response = $this->facebook->sendBatchRequest($requests, $token);

		return $batch_response;
	}

In the above example, the method will be accepting $post_data as a parameter. If a post example is considered, a single $data will look like


$data = [
			'link' => "https://gullele.com/link-goes-here",
			'message'=>"how to make batch request in facebook api",
			'title'=>"Making Multiple Requests in Facebook",
			'description' => 'In this article I will show you how you can make multiple blog posts to Facebook page with one single request.',
		];

Then the line with $this->facebook->request will create a request object and add it as part of request array. Also mind the $id, each should have unique key in the $request array.

Then Facebook will send you back the response with post id and other lots of information that you might want to keep it for later reference like to get metrics on the post – how many likes, impressions, shares.. which will help you to improve in the long run.

Let me know if you have any questions or other methods.

Using Facebook API to post articles from PHP

How to automatically post to facebook page using PHP

This one is a bit detailed tutorial that is assumed for a novice php programmer who is new to Facebook API

Step 1.
Create a developer account from developer.facebook.com. All you need is your facebook account and you can get a developer account from it.

Step 2.
Create a Facebook page. From your Facebook page, on the top right corner, click on the dropdown menu and hit on create page. Select the type of the page you would like to create and then you have it.

Now what you want to do is, to create an auto post to the facebook page you just created from PHP. Lets say you run a blog or product page and you want to post whenever there is new stuff to be posted to the facebook page automatically.
Continue reading Using Facebook API to post articles from PHP

facebook social marketing

Post to Facebook From app – Using PHP

Post to Facebook programatically

You can post whatever you like from PHP to your or company’s page. Facebook has provided an SDK that makes life easier to post to the Facebook page.

This is ideal if you want to post to facebook, from cron job especially. Or on some event like right after the post in wordpress.

First thing first, you need to have a developer account on Facebook and you can do that easily and free on https://developers.facebook.com

Then you need to create an app. A single page or something like that would work. You will see how to create one when you are setting up your account for developer.

Once you have that, on the left menu, you will see dashboard. This contains important information about the app you will use to interact from your code.
Continue reading Post to Facebook From app – Using PHP

sftp connection

connect to sftp from php

connecting sftp using php

What is SFTP
When to use SFTP
Automating SFTP
What to consider when automating
SFTP download using php code
SFTP upload using php code
List all files on SFTP Server

What is SFTP

SFTP, Secure File Transfer Protocol, is more applicable these days where cyber security is at its peak. Whenever possible, one has to use SFTP as the communications are encrypted.

Most of tools that are used for FTP like filezilla allows using SFTP with minor adjustment. SFTP has to be supported by the server that is providing the FTP server and usually uses different port than that of the FTP.

SFTP is pretty much like FTP as far the connection and usage is concerned. It has just another layer of security to make it more secure while uploading and downloading the file.

Basic server address, username, password and port are still necessary to connect and interact with SFTP server.
Continue reading connect to sftp from php

http post

$_POST vs $HTTP_RAW_POST_DATA vs php://input and enctype

This post will answer the following questions:

  • What is form HTTP Request POST ?
  • What is enctype?
  • How to access the posted values?
  • Why is the $_POST not having any data in it?

What is HTTP Request POST?

Continue reading $_POST vs $HTTP_RAW_POST_DATA vs php://input and enctype

taking off of the airplane

how to deploy symfony application to the production server

Deploy Symfony application to production – setting it live

This is a continuation of deploying symfony application to the server part one

Deploy Symfony application to production part two

4. Installing composer dependencies

Be in your symfony app first

cd /apps/symfony-app

The run the installer here

composer install --no-dev --optimize-autoloader

Under most circumstances, this will run without any problem. If there are any problems, composer will log them for you so follow those and solve those. And this will create a vendor folder in the folder you run composer. Continue reading how to deploy symfony application to the production server

airplane in he runway

Deploying Symfony on Production Server

Time to ship your symfony app to production? Here are some flight checks. Lets assume your symfony app is in folder symfony-app

1. Don’t put Symfony app in the public accessible folder on your server

If your servers public facing folder is, say, /var/www/html, then don’t put the whole symfony folder there.

Choose another deeper and non-public facing folder. Let say /apps/symfony-app. I will list how you would put the public facing folders later.
For this to happen run this command on your server

mkdir /apps

2. Pushing your code to production server

You can use FTP client like filezilla or cyberduck and put your code in /apps
If you are using git, then you can clone your app like this

cd /apps
git clone https://username@bitbucket.org/username/symfony-app.git symfony-app

Continue reading Deploying Symfony on Production Server

test

Run single phpunit test

Well, we all love php unit tests :). There are times we would like to run one/single test from test suite that has failed so that we can fix or look at it thoroughly. PHPUnit has a way to do it.
The problem, when you are your php unit suite as

phpunit -c /testFolder..

All you php tests would run.
The solution for this is:
Let’s assume you have this particular php unit test in one of your test files

public function testPhpIsAwesomeOrNot(){
}

All you have to do is to add the <b>group annotation</b> above the function of your php unit test

/**
 * @group awesome
 */
public function testPhpIsAwesomeOrNot(){}

and run your PHPUnit single test wiht –group annotation

phpunit -c /testfolder --group awesome

The above would run single PHPUnit test from the test suite.