Category Archives: api

Unable to Open Proccess with PID 4 , problem port 80 and Apache

Problem detected! 3:19:55 AM [Apache] Port 80 in use by "Unable to open process" with PID 4! 3:19:55 AM [Apache] Apache WILL NOT start without the configured ports free! 3:19:55 AM [Apache] You need to uninstall/disable/reconfigure the blocking application 3:19:55 AM [Apache] or configure Apache and the Control Panel to listen on a different port

How can i solve the php control panel PID problem.

Laravel and passport: POST method returns MethodNotAllowedHttpException

I've been looking all over the internet for 2 days for a solution for my problem to no avail. I'm new to Laravel and API's as a whole, so bear with me.

I've managed to create a working REST API with the use of passport via composer:

The routes in routes/api.php:

Route::post('login', '[email protected]');
Route::post('register', '[email protected]');

And the controller code for login and register:

public function login(Request $request){
    $validator = Validator::make($request->all(), [
        'email' => 'required|email',
        'password' => 'required'
    ]);

    if ($validator->fails()) {
        return response()->json(['error'=>$validator->errors()], 401);            
    }

    if(Auth::attempt(['email' => request('email'), 'password' => request('password')])){
        $user = Auth::user();
        $success['token'] =  $user->createToken('MyApp')->accessToken;
        return response()->json(['success' => $success], 200);
    }
    else{
        return response()->json(['error'=>'Unauthorised'], 401);
    }
}

public function register(Request $request)
{
    $validator = Validator::make($request->all(), [
        'name' => 'required',
        'email' => 'required|email',
        'password' => 'required'
    ]);

    if ($validator->fails()) {
        return response()->json(['error'=>$validator->errors()], 401);            
    }

    $input = $request->all();
    $input['password'] = bcrypt($input['password']);
    $user = User::create($input);
    $success['token'] =  $user->createToken('MyApp')->accessToken;
    $success['name'] =  $user->name;
    return response()->json(['success'=>$success], 200);
}

This API works on localhost but not when i open to the internet with:

php artisan serve --host 192.168.x.x --port 80 

connected to a bought domain via port forwarding.

only the GET methods works, but the POST methods gives the error:

405 Method Not Allowed

As far as i could figure out, it has something to do with redirecting from http to https:

I have a same problem on a half of month ago. The reason is when I post on valid route, it redirects from http to https (configured by .htaccess), so "POST" method becomes "GET" and you see a MethodNotAllowedException.
Check your browser and follow the request, you may see the accurate problem.

from Laravel: POST method returns MethodNotAllowedHttpException

If this is the case for me as well, how do I fix the problem? The .htaccess file has nothing with https in it. Sorry if the answer is in the quoted answer but it don't know how to use that information.

Can’t get correct response after redirecting API requests using htaccess

I have an old domain used for API requests something like this:

https://subdomain.domain.com/api/controller/method

I want to redirect this to a new domain like this:

http://newdomain.com/api/controller/method

So I try this htaccess code:

RewriteEngine on
RewriteRule (.*) http://lcwhapienv.eu-central-1.elasticbeanstalk.com/$1 [R=301,L]

I don't get redirection errors but I always get this response

{
"message": false,
"response": 0
}

this response comes from the API as the request fails so I return message and response 0. So how can I fix this to send or receive the correct data?

Thanks in advance.

Can’t get correct response after redirecting API requests using htaccess

I have an old domain used for API requests something like this:

https://subdomain.domain.com/api/controller/method

I want to redirect this to a new domain like this:

http://newdomain.com/api/controller/method

So I try this htaccess code:

RewriteEngine on
RewriteRule (.*) http://lcwhapienv.eu-central-1.elasticbeanstalk.com/$1 [R=301,L]

I don't get redirection errors but I always get this response

{
"message": false,
"response": 0
}

this response comes from the API as the request fails so I return message and response 0. So how can I fix this to send or receive the correct data?

Thanks in advance.

DateTimeZone Errors [on hold]

When I'm Trying to enter website , blank(white) page opens. I don't know what wrong with my php, I took something from apache errors.

Apache2/Errors log

 PHP Warning:  session_start(): open(/home/frontend_sessions/sess_5gui667au5hduqvt927a92t7r1, O_RDWR) failed: No such file or directory (2) in /var/www/html/frontend/lib/common.php on line 52
 PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 92
 PHP Notice:  date_default_timezone_set(): Timezone ID '' is invalid in /var/www/html/frontend/lib/common.php on line 92
 PHP Notice:  Undefined property: object::$default_timezone in /var/www/html/frontend/lib/common.php on line 93
PHP Fatal error:  Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone () in /var/www/html/frontend/lib/common.php:93\nStack trace:\n#0 /var/www/html/frontend/lib/common.php(93): DateTimeZone->__construct('')\n#1 /var/www/html/frontend/htdocs/index.php(4): include('/var/www/html/f...')\n#2 {main}\n  thrown in /var/www/html/frontend/lib/common.php on line 93
PHP Warning:  Unknown: open(/home/frontend_sessions/sess_5gui667au5hduqvt927a92t7r1, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/home/frontend_sessions) in Unknown on line 0

Line 52

$sessionValue = session_start();

LİNE 92-93

date_default_timezone_set($CFG->default_timezone);
$dtz = new DateTimeZone($CFG->default_timezone);

frontend/cfg

 <?php
    class object {}
    $CFG = new object();
    if ($_SERVER['SERVER_NAME'] == 'localhost') {
        $base_url = "http://xxxxx.com/bit_live/";
        $CFG->api_url = $base_url.'api/htdocs/api.php';
        $CFG->auth_login_url = $base_url.'auth/htdocs/login.php';
        $CFG->auth_verify_token_url = $base_url.'auth/htdocs/verify_token.php';
    } else {
        $base_url = "http://xxxx.com/bit_live/";
    $CFG->api_url = 'https://api.xxxx.com/api.php';
    $CFG->auth_login_url = 'https://auth.xxx.com/login.php';
    $CFG->auth_verify_token_url = 'https://auth.xxx.com/verify_token.php';
    }


    ?>

.Api/cfg maybe mistake is here

   <?php
    class object {}
    $CFG = new object();
    if ($_SERVER['SERVER_NAME'] == 'localhost') {
        $CFG->dbhost = "localhost";
        $CFG->dbname = "xxx";
        $CFG->dbuser = "root";
        $CFG->dbpass = "xxx";
    } else {
        $CFG->dbhost = "localhost";
    $CFG->dbname = "xxx";
    $CFG->dbuser = "root";
    $CFG->dbpass = "xxx";
    }


    ?>

I have like that errors about timezone I don't know what should l do If you can help me I will be happy :)

Apache Ignite Locks for synchronizing arbitrary computation across the grid

I have a simple question for which I can't really find a definitive answer in the Apache Ignite docs.

I see that there is an API in Apache Ignite to create a explicit lock. I understand that these locks are used for writing cache entries and this is done implicitly.

However, can I (should I) be able to explicitly create a Lock in my grid to synchronizing computation some arbitrary code. Here's what I'm thinking of doing:

  1. Request comes into my API.
  2. I try to enter a lock on my Ignite cache
  3. If I can enter the lock I do some calculation (which should only be done on one of my API instances at any given time)
  4. If I can't enter the lock, I return 409 error code (duplicate request)
  5. I exit the lock

Are there potential caveats to doing this? Should I watch out for potential pitfalls?

URL Rewrite For API – Check Request From URL

I have two questions
Q1 : how can i rewrite this url with htaccess ?

localhost/?api=ASdhUAe2Q48
To => localhost/ASdhUAe2Q48/

Q2 : how can i check the request for get data are from wich url ?
it's meant for example :
i have this website : www.me.com
and your website is : www.you.com
now when you want to get data from my website with cURL or file_get_content or etc. i should know that this url is avalable or not (in mysql)
i have this mysql table for API :

users_api => { api_id , users_id , api_key , api_name , api_url }


Thanks and sorry for my poor english.


Edit : I found awnser #1 :

RewriteRule ([^/]*)/$ /index.php?api=$1[L]