我正在使用Guzzle并发请求工具:http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests
我的代码类似于示例代码:
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new Client();
$requests = function ($total) {
$uri = 'http://127.0.0.1:8126/guzzle-server/perf';
for ($i = 0; $i < $total; $i++) {
yield new Request('GET', $uri);
}
};
$pool = new Pool($client, $requests(100), [
'concurrency' => 5,
'fulfilled' => function ($response, $index) {
// this is delivered each successful response
},
'rejected' => function ($reason, $index) {
// this is delivered each failed request
},
]);
// Initiate the transfers and …Run Code Online (Sandbox Code Playgroud) 我有以下表格
我有以下型号:
class User {
public function favouriteBooks()
{
return $this->belongsToMany(Book::class, 'favourite_books');
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得属于用户的所有ID.
我目前这样做的方式是这样的:
$user->favouriteBooks()->select('book_id')->get();
Run Code Online (Sandbox Code Playgroud)
然而,这会返回数据;
[
{
"book_id": 23,
"pivot": {
"user_id": 57,
"book_id": 23
}
},
{
"book_id": 41,
"pivot": {
"user_id": 57,
"book_id": 41
}
},
...
]
Run Code Online (Sandbox Code Playgroud)
我希望它像这样返回数据:
[
23,
41,
...
]
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有以下代码:
$fb = new Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.9',
]);
$oAuth2Client = $fb->getOAuth2Client();
$tokenMetaData = $oAuth2Client->debugToken($accessToken);
dump($tokenMetaData);
$graphUser = $fb->get('/me?fields=first_name,last_name,email', $accessToken)->getGraphUser()->asArray();
dump($graphUser);
Run Code Online (Sandbox Code Playgroud)
上面的输出如下:
$ metaData:
[
"app_id" => "..."
"application" => "My App Name"
"expires_at" => "2017-07-01 11:40:09.000000"
"is_valid" => true
"issued_at" => "2017-05-02 11:40:09.000000"
"metadata" => array:2 [
"auth_type" => "rerequest"
"sso" => "ios"
]
"scopes" => array:2 [
0 => "email"
1 => "public_profile"
]
"user_id" => "102..."
]
}
Run Code Online (Sandbox Code Playgroud)
$ graphUser …
我试图从 Git 历史记录中永久删除一个文件,因为它包含敏感数据。
为此,我使用bfg:https : //rtyley.github.io/bfg-repo-cleaner/
该文件名为app/config.json.
但是config.json,我不想删除其他文件夹中调用的其他文件。
我尝试了以下方法:
git clone --mirror git://example.com/some-repo.git
bfg --delete-files app/config.json my-repo.git
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息:
Error: *** Can only match on filename, NOT path *** - remove '/' path segments
Run Code Online (Sandbox Code Playgroud)
如何仅删除此特定文件?
我想使用JavaScript创建一个输入,自动使用正确的信用卡格式对其进行格式化.
我想要的是?
1234567890123456,则应将其格式化为1234 5678 9012 34561234567890123456789它应格式化为"1234 5678 9012 3456"564adsd299 474它应格式化为"5642 9947 4"输入还应该尊重文本框的传统行为.(|这里类似于光标,例如
如果我在输入时输入8:
1234 5|67 它应该转向 1234 58|671234|,它应该转向 1234 8 1234| 567 它应该转向 1234 85671234| 5679 它应该转向 1234 8567 9如果我在输入时删除了前一个字符:
1234 5|67 它应该转向 1234 |671234 |567 它应该转向 1234| 5671234| 567 它应该转向 123|5 67可能会有更多的测试用例.
例
基本上它应该与Google Play商店中使用的"输入卡片详细信息"完全相同.要查找此页面:在Android设备上打开Play商店>单击帐户>付款方式>添加信用卡或借记卡.此屏幕也可在此处找到:https://play.google.com/store/account
到目前为止我有什么?
这是我到目前为止:
var txtCardNumber = document.querySelector("#txtCardNumber");
txtCardNumber.addEventListener("input", onChangeTxtCardNumber);
function onChangeTxtCardNumber(e) …Run Code Online (Sandbox Code Playgroud)我正在尝试在 xquery 中创建类似哈希映射/键值对的结构。我知道 xquery 中存在类似地图的结构:http://www.w3.org/2005/xpath-functions/map/
甚至在撒克逊语中找到了文档:http://www.saxonica.com/html/documentation/functions/map/
但是我不确定如何创建或使用地图。
到目前为止,这是我的代码:
declare namespace map="http://www.w3.org/2005/xpath-functions/map";
let $a := map:map()
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
Cannot find a matching 1-argument function named
{http://www.w3.org/2005/xpath-functions/map}map()
Run Code Online (Sandbox Code Playgroud)
那么我到底如何在 xquery 中使用映射呢?
我为我的单元测试定义了一个phpunit.xml配置文件.在这个文件中,我指示在单元测试结果中显示颜色如下:
<phpunit
...
colors="true"
...
</phpunit>
Run Code Online (Sandbox Code Playgroud)
当我在命令行中运行测试时,一切正常,除了我在结果中没有绿色和红色.
如果我删除配置文件并--color=always在命令行中使用该参数,那么我将获得带有颜色的结果.
在配置文件中,我已经尝试更改colors="true"为colors="always"没有结果.
我的配置文件有问题吗?
这是我的phpunit.xml配置文件:
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.1/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<testsuites>
<testsuite name="examples">
<directory>/home/miguelbgouveia/Documents/projects/joomla/tests</directory>
<file>test_example.php</file>
</testsuite>
</testsuites>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
phpunit的版本是5.1.2
我在页面底部添加了jQuery.但是,当我在pagespeed见解(移动)上运行我的网站时,我收到错误:
在上层内容中消除渲染阻止JavaScript和CSS您的页面有2个阻止脚本资源和1个阻止CSS资源.
这会导致呈现页面的延迟.在不等待加载以下资源的情况下,无法呈现页面上的上述内容.
尝试推迟或异步加载阻止资源,或直接在HTML中内联这些资源的关键部分.
请参阅:http://learnyourbubble.com和https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Flearnyourbubble.com&tab=mobile
但是,jQuery添加在页面底部.所以它应该低于一点.
如何删除此错误?
我想使用PHP来检查是否有任何内容正在侦听localhost:81,以确保可以运行PHP内置服务器.
即我想检查以下是否正常运行php -S localhost:81.
现在如果某些东西已经在端口81上监听(例如Apache),这当然会引起问题.
我读了以下内容:如何检查端口465和587是否使用PHP打开?并且解决方案似乎不起作用.
即:
$fp = fsockopen('localhost', '81', $errno, $errstr, 5);
var_dump($fp); // returns false
if (!$fp) {
// port is closed or blocked
echo "CLOSED!";
return false;
} else {
// port is open and available
echo "OPEN!";
fclose($fp);
return true;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,上面不断回归"关闭!" 即使它没有.
我还收到以下错误消息:
PHP Warning: fsockopen(): unable to connect to localhost:81 (Connection refused)
Run Code Online (Sandbox Code Playgroud)
我该如何解决我的问题?
还有其他选择吗?
我有 2 个数字范围:
$startTime到$endTime$offerStartTime到$offerEndTime上述每个变量都是整数。
我想看看 的范围是否offerStartTime落在和 的offerEndTime范围内。startTimeendTime
例如,如果startTime和endTime范围为:10 到 20,则以下示例范围将返回true:
offerStartTime: 5, offerEndTime: 11offerStartTime: 5, offerEndTime: 100offerStartTime: 10, offerEndTime: 15offerStartTime: 10, offerEndTime: 100offerStartTime: 12, offerEndTime: 15offerStartTime: 19, offerEndTime: 100将返回以下内容false:
offerStartTime: 1, offerEndTime: 3offerStartTime: 90, offerEndTime: 100offerStartTime: 1, offerEndTime: 10offerStartTime: 20, offerEndTime: 100我怎样才能做到这一点?理想情况下希望用 PHP 提供答案,但伪代码就可以了。