I got problem about using use curl_init() on the same domain and server. I have 2 Laravel projects on same environment run with xampp (window). Project A is API use database name X(RDS) Project B call API use database name Y(MySql)
Example URL
Project A ww.example/project_a/
Project B ww.example/project_b/
Problem
Project B use curl_init() call API from Project A for get data from database X(RDS), but Project A try to find database X in MySql(Project B connection) and then error.
I already tried to make both project run on different server it can work. Do I have to config something?
Here .env of both
Project A
APP_NAME= A
APP_ENV=local
APP_KEY=XXXXXXXXXXXXX
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=rds
DB_HOST=rds_url
DB_PORT=3306
DB_DATABASE=X
DB_USERNAME=xx
DB_PASSWORD=xx
Project B
APP_NAME_B= B
APP_ENV_B=local
APP_KEY_B=YYYYYYYYYYYYY
APP_DEBUG_B=false
APP_LOG_LEVEL_B=debug
APP_URL_B=http://localhost
DB_CONNECTION_B=mysql
DB_HOST_B=127.0.0.1
DB_PORT_B=3306
DB_DATABASE_B=Y
DB_USERNAME_B=yy
DB_PASSWORD_B=yy
Curl
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://ww.example/project_a/booking-box/get-data-by-api",
CURLOPT_COOKIESESSION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
//"authorization: ",
"cache-control: no-cache",
"content-type: Application/json"
),
));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
Error Because Project A can't find X in Mysql
"SQLSTATE[HY000] [1049] Unknown database 'X' (SQL: select * from `...` where `...` = 1 limit 1)"
Also already try this but not work Two Laravel applications on the same server conflicting with one another