Friday, August 3, 2018

Create Auto Backup Database on Linux


apt-get install cron

crontab -e

#!/bin/sh
 mysqldump -u root -pQidDniuJMb@LC@G5 gift > /var/bin/db/gift/gift.sql
 cd /var/bin/db/gift/
 tar -zcvf giftsql_$(date +%d%m%y).tgz *.sql
 find -name '*.tgz' -type f -mtime +2 -exec rm -f {} \;

0 * * * * /var/bin/mysqlbackup.sh


*/3 * * * * /var/bin/executedb.sh

Thursday, August 2, 2018

Basic Auth with PHP


// basic auth
if (
   !isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) ||
   ($_SERVER['PHP_AUTH_USER'] !== 'admin' && $_SERVER['PHP_AUTH_PW'] !== 'test')) {
    header('WWW-Authenticate: Basic realm="Enter username and password for admin page."');
    header('Content-Type: text/plain; charset=utf-8');
    die('このページを見るにはログインが必要です。');
    header('Content-Type: text/html; charset=utf-8');
}

Tuesday, July 26, 2016

How to get pins from pinterest with Jquery



If you are familiar with PHP you can just use these existing projects from github

1- Pinterest API - PHP

Read more

To use the Pinterest API you have to register yourself as a developer and create an application. After you've created your app you will receive a app_id and app_secret.


2- Pinterest Bot for PHP

This PHP library will help you to work with your Pinterest account without using any API account credentials.

To have an access to Pinterest API you need to go to developers.pinterest.com and register as a developer, then register your application, then wait for confirmation, and only then you will get an access token. With this library you are already ready to go. Just use only your account login and password, like you do it in your browser. But even your account is not required, if your don't use such operations as creating pins, writing comments or sending messages!

Read more


So, in this case I would not follow the PHP code because it would hard for the beginner. I gonna work with jQuery instead in just a few line of code but the result will produce the landslide victories.

1- Copy the somebody pinterest name or your. ex : https://www.pinterest.com/{nameofsomeone}/
2- Create the function to get the request pins from url
3- Extract the object.

See Example

Monday, July 25, 2016

How to check Cron jobs



In the previous article I have shown you to configure cron jobs. Somebody asked me how to check weather cron jons is processing.

So, if you haven't known what is cron jobs please read follow this cron jobs

There are many way to check your cron jobs. To do it you have to :

1- Turn on your terminal and type

   -> service crond status (it will show your cron is running or not)

2- you can test it directly with your Shell

    -> cd /var/www/vhost/yourroot/html/app
   -> Console/cake News (if your code error it will be written into log file)

I hope this two steps will be able to involve your part. so if you think this article is important please help to share to everyone.


Set up cron jobs or crontab in Cakephp




Before stating to set up Cron jobs in your server you have understand and know what the Cron jobs is?

Cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful to automate repetitive tasks.

Cron syntax
  */5  *    *    *    *  cd /full/path/to/app && Console/cake myshell myparam
# *    *    *    *    *  command to execute
# │    │    │    │    │
# │    │    │    │    │
# │    │    │    │    \───── day of week (0 - 6) (0 to 6 are Sunday to Saturday,
# |    |    |    |           or use names)
# │    │    │    \────────── month (1 - 12)
# │    │    \─────────────── day of month (1 - 31)
# │    \──────────────────── hour (0 - 23)
# \───────────────────────── min (0 - 59)
To understand more please follow this link console-and-shells

1 - Create model News.php
App::uses('AppModel', 'Model');
class News extends AppModel
{
    public function sendNews()
    {
 $this->updateAll(array('is_disabled' => 1), array('delivery_time' => date('H:i').':00'));
    }
}

2- Create NewsSell in Cosole.

class NewsSell extends AppShell
{
   public function main()
   {
    App::import('Model', 'News');
    $News  = new News();
    $News->sendNews();
   }
}

3- Write command in crontab

-> type "crontab -e" in your terminal
->  set cron path "*/1 * * * * /var/www/vhosts/yourwebroot/html/app/Console/cake News"
-> save

Finally, I hope that this article will help you to get reach at the point.

Problem with cron jobs cakephp.





Tuesday, April 5, 2016

Sunday, March 27, 2016

Websocket with PHP


There are many ways to create real time web application with PHP, but in this
case I will show you a best websocket library will be useful for making a real
time web application.

What is Websockt?

It is full-duplex (data can transmitted in both directions) clinet/Server commnuication over TCP.
so you will find out that websocket is the new feature of HTML5 that allow Client script to open
the bi-directional socket connections to a server. Now it work on Chrome, Firefox, Safari, Opera
and other browser even on mobile.

What is PHPWebsockets?

It is websocket libray server which written in PHP. You can
download from there : https://github.com/ghedipunk/PHP-WebSockets

testwebsock.php
#!/usr/bin/env php
send($user,$message);
  }
  
  protected function connected ($user) {
    // Do nothing: This is just an echo server, there's no need to track the user.
    // However, if we did care about the users, we would probably have a cookie to
    // parse at this step, would be looking them up in permanent storage, etc.
  }
  
  protected function closed ($user) {
    // Do nothing: This is where cleanup would go, in case the user had any sort of
    // open files or other objects associated with them.  This runs after the socket 
    // has been closed, so there is no need to clean up the socket itself here.
  }
}
$echo = new echoServer("0.0.0.0","9000");
try {
  $echo->run();
}
catch (Exception $e) {
  $echo->stdout($e->getMessage());
}


client.html

Please run the client.html and don't forget to lunch the testwebsocket.php via common line.