Php “如何从instagram上获取数据”;“一些”;服务器

Php “如何从instagram上获取数据”;“一些”;服务器,php,instagram,Php,Instagram,我使用此代码登录Instagram API,但在某些服务器上此代码运行正常,在其他服务器上我无法获取Instagram数据。谁知道为什么 <?php require 'instagram.class.php'; require 'instagram.config.php'; // Receive OAuth code parameter $code = $_GET['code']; // Check whether the user has granted access if (tr

我使用此代码登录Instagram API,但在某些服务器上此代码运行正常,在其他服务器上我无法获取Instagram数据。谁知道为什么

<?php

require 'instagram.class.php';
require 'instagram.config.php';

// Receive OAuth code parameter
$code = $_GET['code'];

// Check whether the user has granted access
if (true === isset($code)) {

// Receive OAuth token object
$data = $instagram->getOAuthToken($code );

if(empty($data->user->username))
{
echo "1";

}
else
{
    session_start();
    $_SESSION['userdetails']=$data;
    echo $user=$data->user->username;
echo    $fullname=$data->user->full_name;
echo    $bio=$data->user->bio;
echo    $website=$data->user->website;
echo    $id=$data->user->id;
echo    $token=$data->access_token;


}
} 
else 
{
// Check whether an error occurred
if (true === isset($_GET['error'])) 
{
    echo 'An error occurred: '.$_GET['error_description'];
}

}

?>

如果在服务器上创建会话,则无法在其他服务器上获取会话。你需要使用粘性会话。我的建议是在你的一台服务器上安装memcache。您可以看到如何安装。安装后,假设memcache服务器路径为
localhost:11211
。您可以将php配置为将会话保存在此memcache服务器中,而不是每个服务器内存中。您需要在
php.ini
中执行以下简单配置:

session.save_handler = memcache 
session.save_path = "tcp://localhost:11211"

当您设置任何会话时,它将在这个memcache服务器上创建,您可以从任何服务器获取它。此设置将应用于所有服务器。您需要为
会话指定服务器名称。在所有服务器中保存路径。因为只有一个memcache服务器

您可能需要启用粘性会话[load balancer],所以我使用memcache作为会话。save_处理程序和php共享相同的会话良好答案-很好的解决方案。Memcache+1