# Http.get calls twice

**URL:** <https://discourse.slimframework.com/t/http-get-calls-twice/2277>\
**Category:** Questions\
**Created:** [March 2, 2018, 10:37pm UTC](https://discourse.slimframework.com/t/http-get-calls-twice/2277 "2018-03-02T22:37:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiminkibu](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kiminkibu](https://discourse.slimframework.com/u/kiminkibu)\
**Post date:** [March 2, 2018, 10:37pm UTC](https://discourse.slimframework.com/t/http-get-calls-twice/2277/1 "2018-03-02T22:37:06Z")

</div>

Hi,  
When I use http.get from app it calls once but executed twice on api.  
So, when I say if record doesn’t exist add record, else return error.  
It adds the record and returns the error.

even this logs twice  
$app-\>get(’/store/purchase/item’, function () use ($app, $config, $store\_model) {  
error\_log(“entered”);

I couldn’t find the solution so far.  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 3, 2018, 12:16pm UTC](https://discourse.slimframework.com/t/http-get-calls-twice/2277/2 "2018-03-03T12:16:20Z")

</div>

What does your `index.php` file look like? Are you perhaps calling `$app->run()` more than once? Are you possibly including a routes file more than once? If you manually error, can you follow the stack trace and see where things are duplicating? Do you have Xdebug running so you can manually step through and see where things are looping?

---

<div class="post-metadata">

**Author:** ![kiminkibu](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kiminkibu](https://discourse.slimframework.com/u/kiminkibu)\
**Post date:** [March 5, 2018, 12:16pm UTC](https://discourse.slimframework.com/t/http-get-calls-twice/2277/3 "2018-03-05T12:16:09Z")

</div>

Here is my index.php  
I think there is a problem with the plugin I use on ionic. I’ll check that again.  
I haven’t use Xdebug, I’ll check that too.  
Thanks

```
<?php

error_reporting(E_ALL);

// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
//header('Access-Control-Max-Age: 0');
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
    header("Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
    header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}

require 'vendor/autoload.php';

include 'src/Model.php';
include 'src/UserModel.php';
include 'src/GameModel.php';
include 'src/StoreModel.php';
include 'src/Config.php';

$config = new Config();
$user_model = new UserModel($config->getDatabaseInfo());
$game_model = new GameModel($config->getDatabaseInfo());
$store_model = new StoreModel($config->getDatabaseInfo());

$app = new \Slim\Slim(array(
'debug' => true
));

include 'src/user.php';
include 'src/game.php';
include 'src/store.php';

$app->get('/', function() use($app) {
   // $app->response->setStatus(200);
echo "Welcome to Slim 3.0 based API";
});

$app->run();
```

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [March 16, 2018, 10:00pm UTC](https://discourse.slimframework.com/t/http-get-calls-twice/2277/4 "2018-03-16T22:00:52Z")

</div>

> [@kiminkibu](#):
>
> echo “Welcome to Slim 3.0 based API”;

It looks like a Slim 2.0 application:

```php
$app = new \Slim\Slim(array(
'debug' => true
));

```
