Friday, March 29, 2013

HTTP access control (CORS)

Sometimes if we used XMLHttpRequest in javascript it gives us error:

Origin http://examplehost:80/ is not allowed by Access-Control-Allow-Origin.

This error means that the server side don't allow the requests from different domain so in this example if the server side is working also in http://examplehost:80 it will be working without problems.
so how we can solve this problem?!

Firstly we need to know what is The Cross-Origin Resource Sharing standard ...
It works by adding new HTTP headers that allow servers to describe the set of origins that are permitted to read that information using a web browser.  Additionally, for HTTP request methods that can cause side-effects on user data (in particular, for HTTP methods other than GET, or for POST usage with certain MIME types), the specification mandates that browsers "preflight" the request, soliciting supported methods from the server with an HTTP OPTIONS request header, and then, upon "approval" from the server, sending the actual request with the actual HTTP request method.  Servers can also notify clients whether "credentials" (including Cookies and HTTP Authentication data) should be sent with requests.

we can use  Cross-Origin Resource Sharing standard by adding
 Access-Control-Allow-Origin: <origin> | *  <origin> is a specific domain name.
in the response header so this mean that the server will accept the XMLHttpRequest of this domain or * which means any domain.
they are many options in Cross-Origin we can know it from

https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS

Regards,

Friday, February 1, 2013

Web Services load testing using Pylot

After developing web services we may need to make a load testing for it to test how many agents the web service can serve in the same time.
We can do this load testing using many tools but today we found an open source python project (Pylot)

By this project we can run some test cases with different configurations like:
  1. Number of agents.
  2. Test Duration.
  3. Time between each user.
and there are many configurations can be set using GUI or from command line before running the testing script.

All test cases are written in a XML file and every agent run it.

The Result of the test will be generated in HTML file which will have something like:
  1. The Average Response Time.
  2. The Minimum Response Time.
  3. The Maximum Response Time.
  4. The ST.DEV.
  5. Number of Requests made by Agents.
  6. Number of failed requests.
  7. Errors Returned from web services.
Pylot website: http://pylot.org/ 
To download Pylot project: http://pylot.org/download.html
For more installation details: http://pylot.org/gettingstarted.html 

Regards,

Monday, January 21, 2013

Linux Server Time

Linux servers time may be not adjusted to the local time zone so it may make some problem if we use the time in any process in our project.
To know the current time of the server:

1- Login to ssh.
2- Type the date command: date
3- The result will be something like that: Mon Jan 21 04:24:53 EST 2013

All Times are saved in a folder in the system its path is: /usr/share/zoneinfo/

and the local time of the server in the file its path is: /etc/localtime

We can change it to the local time zone by one command:
cp /usr/share/zoneinfo/Egypt /etc/localtime

Now if we type date it will return the local time of Egypt...

Regards,

Monday, January 14, 2013

MySQL Logs

MySQL have many types of logs which make debugging more easily...
To know logs are enabled or not we should follow this steps:
1- Login using SSH
2- Connect to mysql server: mysql -u[username] -p[password]
3- Run : mysql> show variables like '%log%';
The Result of query will be some thing like this:

+---------------------------------+---------------------------+
| Variable_name                   | Value                     |
+---------------------------------+---------------------------+
| log                             | ON                        | 
| log_bin                         | OFF                       | 
| log_bin_trust_function_creators | OFF                       | 
| log_error                       | /var/log/mysqld.error.log | 
| log_slow_queries                | OFF                       | 
+---------------------------------+---------------------------+
26 rows in set (0.00 sec)

as we see the logs are not enabled so we need to enable it using some steps:
1- open my.cnf file (may be in /etc/mysql/my.cnf)
2- find [mysqld] section and write

log-bin
log
log-error
log-slow-queries
below it.
3- save the file and restart mysql service: sudo restart mysql
The logs will be created, by default, in the same data directory that holds the database subdirectories themselves (typically /var/lib/mysql) and the log file names default to the hostname followed by a suffix that matches the directive names above (eg. -bin, -slow-queries, etc).
Sources:
1- http://dev.mysql.com/doc/refman/5.0/en/server-logs.html
2- http://serverfault.com/questions/71071/how-to-enable-mysql-logging

Saturday, January 12, 2013

Description

 . . . بسم الله الرحمن الرحيم . . .
This Blog will have any experience i gain from my study, my work or my life. . .
Aiming to be a good source for any problem solution. . .

Regards,