A Web service
is the method of communications over Internet between two electronic devices.
WWW is know as Internet, but WWW is a set of the protocols.
WWW components:
HTTP is the fact protocol used over internet .
HTTP is made by Socket, the Socket is IP/Port. We have 2 kind of sockets TCP/UDP.
HTML is the view of HTTP for human.
Wednesday, March 19, 2014
Bankier's Algorithm
The Banker's algorithm is run by the operating system whenever a process requests resources. The algorithm avoids deadlock by denying or postponing the request if it determines that accepting the request could put the system in an unsafe state (one where deadlock could occur). When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time.
Resources
For the Banker's algorithm to work, it needs to know three things:
How much of each resource each process could possibly request[CLAIMS]
How much of each resource each process is currently holding[ALLOCATED]
How much of each resource the system currently has available[AVAILABLE]
Resources may be allocated to a process only if it satisfies the following conditions:
request ≤ max, else set error condition as process has crossed maximum claim made by it.
request ≤ available, else process waits until resources are available.
Some of the resources that are tracked in real systems are memory, semaphores and interface access.
The Banker's Algorithm derives its name from the fact that this algorithm could be used in a banking system to ensure that the bank does not run out of resources, because the bank would never allocate its money in such a way that it can no longer satisfy the needs of all its customers. By using the Banker's algorithm, the bank ensures that when customers request money the bank never leaves a safe state. If the customer's request does not cause the bank to leave a safe state, the cash will be allocated, otherwise the customer must wait until some other customer deposits enough.
Basic data structures to be maintained to implement the Banker's Algorithm:
Let n be the number of processes in the system and m be the number of resource types. Then we need the following data structures:
Available: A vector of length m indicates the number of available resources of each type. If Available[j] = k, there are k instances of resource type Rj available.
Max: An n×m matrix defines the maximum demand of each process. If Max[i,j] = k, then Pi may request at most k instances of resource type Rj.
Allocation: An n×m matrix defines the number of resources of each type currently allocated to each process. If Allocation[i,j] = k, then process Pi is currently allocated k instances of resource type Rj.
Need: An n×m matrix indicates the remaining resource need of each process. If Need[i,j] = k, then Pi may need k more instances of resource type Rj to complete the task.
Note: Need[i,j] = Max[i,j] - Allocation[i,j].
video
Monday, March 17, 2014
ZF2 about Session & Serialize
Key concept of the Exam is Session:
Session
support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
ZF2 & Sessions
Another concept what we should know is
Serialize
Generates a storable representation of a value.
This is useful for storing or passing PHP values around without losing their type and structure.
To make the serialized string into a PHP value again, use unserialize().
Thursday, March 13, 2014
How to Reset MACOS Password
- Restart the Mac holding down the Command+S keys
- You’ll need to check the filesystem first:
- Next, you must mount the root drive as writeable so that changes will save:
- Now, type the following command exactly, followed by the enter key:
fsck -fymount -uw /rm /var/db/.applesetupdoneshtudown -h nowTuesday, March 11, 2014
Friday, March 7, 2014
WebService ZF2 (RESTful)
RESTful Services made easy with ZF2.
Thera are many ways (technologies) to implement a web-services.
ZF2 Fundamentals:
• PHP 5.3.3+ (and tested on 5.4, as well as upcoming
5.5)
• Modular & flexible (ModuleManager)
• Event-driven (EventManager)
• Leverage Inversion of Control (ServiceManager)
• Re-written MVC, Forms, I18n, Db, and more
Event Example by Rob Allen:
Simple example
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
};
$events = new EventManager();
$events->attach('eventName', $callback);
echo "\nRaise an event\n";
$events->trigger('eventName');
LISTENER
Listeners
Just a function (Any callback)
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
var_dump($event->getTarget());
var_dump($event->getParams());
};
$events = $someObject->getEventManager();
$events->attach('eventName', $callback);
Thera are many ways (technologies) to implement a web-services.
- Representation State Transfer or REST , that it has been preferred for web services used in web applications.
- SOAP web service, also know as WS-* Stack, is also popular alternative.
But REST has been more popular over web developers.
What is REST:
According to Abeysinghe "
REST is a software architecture style that can be followed while designing software systems. REST is an ideal design style to be followed for web services based software applications."
The key REST principles in brief:
- Provide every resource with a unique ID, for example, a URI Link resources with each other, establishing relationships among resources
- Use standard methods (HTTP, media types, XML)
- Resources can have multiple representations that reflect different application states
- The communication should be stateless using the HTTP
Rob Allen said that principal Constraints are:
- Client/Server
- Stateless
- No client context stored between requests. This means no sessions.
- Cacheable
- Non-idepoment methos should allow client to cache responses.
- Clients should honor HTTP headers with respect to caching.
- Layered system
- Client should not care whether it is connected.
- Uniform Interface
- Identification of resources
- Manipulation of resources through representations
- Self-descriptive messages
- Hypermedia as the engine of application state.
• PHP 5.3.3+ (and tested on 5.4, as well as upcoming
5.5)
• Modular & flexible (ModuleManager)
• Event-driven (EventManager)
• Leverage Inversion of Control (ServiceManager)
• Re-written MVC, Forms, I18n, Db, and more
Event Example by Rob Allen:
Simple example
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
};
$events = new EventManager();
$events->attach('eventName', $callback);
echo "\nRaise an event\n";
$events->trigger('eventName');
LISTENER
Listeners
Just a function (Any callback)
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
var_dump($event->getTarget());
var_dump($event->getParams());
};
$events = $someObject->getEventManager();
$events->attach('eventName', $callback);
TARGET
Compose an EventManager within a class…
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
class MyTarget
{
public $events;
public function __construct()
{
$this->events = new EventManager();
}
… and trigger actions within methods.
public function doIt()
{
$event = new Event();
$event->setTarget($this);
$event->setParam('one', 1);
$this->events->trigger('doIt.pre', $event);
// do something here
$this->events->trigger('doIt.post', $event);
}Typical usage
$callback = function ($event) {
echo "Responding to doIt.pre!\n";
var_dump(get_class($event->getTarget()));
var_dump($event->getName());
var_dump($event->getParams());
};
$target= new MyTarget();
$target->events->attach('doIt.pre', $callback);
$target->doIt();
Compose an EventManager within a class…
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
class MyTarget
{
public $events;
public function __construct()
{
$this->events = new EventManager();
}
… and trigger actions within methods.
public function doIt()
{
$event = new Event();
$event->setTarget($this);
$event->setParam('one', 1);
$this->events->trigger('doIt.pre', $event);
// do something here
$this->events->trigger('doIt.post', $event);
}Typical usage
$callback = function ($event) {
echo "Responding to doIt.pre!\n";
var_dump(get_class($event->getTarget()));
var_dump($event->getName());
var_dump($event->getParams());
};
$target= new MyTarget();
$target->events->attach('doIt.pre', $callback);
$target->doIt();
Subscribe to:
Posts (Atom)