我有一个php文件,我有API代码在进行。这个文件正在使用twitter api,在文件中,我通过会话传递用户密钥来处理和发送推文。PHP如何处理同一个文件上的同名变量
我在想,当多个请求在同一秒内到达这个文件时会发生什么?
如果来自不同地理位置的5个请求来到文件..每个变量的值不同......但所有将采用相同的变量名称...... php创建该文件的5个实例来执行推文?
请看看我的代码,看看发生了什么事情:http://pastebin.com/ic6pYLgi
如果有多人将请求发送到该文件会发生什么?
<?php
session_start();
//pass session variables into standard variable
$ck = $_SESSION['consumer_key'];
$cs = $_SESSION['consumer_secret'];
$at = $_SESSION['access_token'];
$ats = $_SESSION['access_token_secret'];
$hashtag = $_SESSION['hashtag'];
$tweet = $_POST['tweet'];
//TODO unset session at end of script
//TODO limit tweet length
if (!empty($ck && $cs && $at && $ats && $tweet)){
$ck = $_POST['consumer_key'] = $ck; //get session value into POST then pass back to variable
$cs = $_POST['consumer_secret'] = $cs;
$at = $_POST['access_token'] = $at;
$ats = $_POST['access_token_secret'] = $ats;
$_POST['tweet'];
$hashtag = $_POST['hashtag'] = $hashtag;
}
require "autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', $ck); // add app consumer key between single quotes
define('CONSUMER_SECRET', $cs); // add app consumer secret key between single quotes
$access_token = $at;
$access_token_secret = $ats;
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
if (!empty($ck && $cs && $at && $ats && $tweet && $hashtag)) {
$hashtag = '#' . $hashtag;
$connection->post('statuses/update',array('status' => $tweet . ' ' . $hashtag));
$t = $connection;
echo '<pre>';
//print_r($t);
echo '</pre>';
echo "Your message has been sent to Twitter with a hashtag.";
}
//TODO Add error handling to send to special inbox
//Tweet without hashtags
if (!empty($ck && $cs && $at && $ats && $tweet) && empty($hashtag)) {
$connection->post('statuses/update',array('status' => $tweet));
//$t = $connection;
//echo '<pre>';
//print_r($t);
//echo '</pre>';
//echo "Your message has been sent to Twitter without a hashtag.";
}
session_destroy(); //this will hopefully help with load on this file
?>
“php是否创建该文件的5个实例”=是。 –
@Dagon是否检出了代码?如果你说的是真的,那我就是金。 –
当人们同时访问同一网页时会发生什么 - 同样的事情 –