php


PHP insert document mLab


I'm new at mLab and trying to insert same simple documents to my mongodb on mLab. First of all I was able to insert some documents to the database using the shell (command line) anytime I run the code I get this error:
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException:
No suitable servers found (`serverSelectionTryOnce` set): [connection timeout calling ismaster on 'ds157390.mlab.com:57390'] in C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php:726
Stack trace: #0 C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php(726): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 C:\xampp\htdocs\MongoDB\azureConnect.php(46): MongoDB\Collection->insertMany(Array) #2 {main} thrown in C:\xampp\htdocs\MongoDB\vendor\mongodb\mongodb\src\Collection.php on line 726
PHP-Code:
<?php
ini_set('max_execution_time', 0);
require 'vendor/autoload.php';
$seedData = array(
array(
'decade' => '1970s',
'artist' => 'Debby Boone',
'song' => 'You Light Up My Life',
'weeksAtOne' => 10
),
array(
'decade' => '1980s',
'artist' => 'Olivia Newton-John',
'song' => 'Physical',
'weeksAtOne' => 10
),
array(
'decade' => '1990s',
'artist' => 'Mariah Carey',
'song' => 'One Sweet Day',
'weeksAtOne' => 16
),
);
$uname = "test";
$pword = "test";
$uri = "mongodb://".$uname.":".$pword."#ds157390.mlab.com:57390/data4estate";
$conn = new MongoDB\Client($uri);
$songs = $conn->data4estate->songs;
$songs->insertMany($seedData);
Try to follow instruction for connection timout:
https://blog.mlab.com/2013/10/do-you-want-a-timeout/
Try to set timeout option to connection string
https://docs.mongodb.com/manual/reference/connection-string/#uri.connectTimeoutMS
$uri = "mongodb://".$uname.":".$pword."#ds157390.mlab.com:57390/data4estate?connectTimeoutMS=300000";
You can set the socketTimeoutMS on php MongoClient as answered here:
PHP MongoDb driver: How to set timeout for executing a code

Related Links

How can I get the (real) HTTP response status code from a CORS request in AngularJS 1.5?
PHP - JSON empty values in database
Find consecutive repited value in array
Ubuntu Apache PHP - Create and write to an Excel Document
PHP fopen() Cannot Execute Opened Php Extension File
Woocommerce two shipping options at same time
PHP- How to create a text file in network shared folder
not getting response from Mixpanel
input of the form is not updating [duplicate]
How to setup Memcached with failover support in Heroku/PHP 5.6 environment?
Cartesian Product on unknown number of php arrays
How can I repeat IF twice or infinite times in PHP? [duplicate]
How to add extension Add global in twig
PhpStorm: Only Link to Function in included Code
I need help writing a small program to randomly draw entries from a list
URL rewriting doesn't work when web-site is accessed via alias directory

Categories

HOME
powerbi
opencart
freeradius
cucumber
openxml
adfs3.0
code-formatting
nsview
celery
amp
stored-procedures
lapack
nsstring
vimeo
mailmerge
jquery-select2-4
webstore
xbox360
mahout-recommender
closures
mixpanel
fosuserbundle
coroutine
codefluent
akka-persistence
el
multi-dimensional-scaling
fstar
hdmi
ccavenue
social-networking
substance
copy-protection
source-insight
windowsiot
kendo-listview
markov-chains
unification
oauth2
export-to-pdf
grails-spring-security
coverage.py
pyttsx
optionaldataexception
dbcc
transparency
nomad
return-type
tinyioc
scala-breeze
winston
datediff
android-mediarecorder
gmaps.js
zend-server
allegro
openquery
msbuild-4.0
declarative
bbc-micro
powerpoint-2013
apache-pig-grunt
django-redis
flush
ioexception
diawi
godeps
miniconda
extend
hmisc
ngcordova
azure-xplat-cli
nssortdescriptor
sql-processor
fasterxml
image-rotation
smacss
nesper
distributed-r
zend-search-lucene
nodeload
pre
django-sites
application-server
tnt4j
bcdedit
delphi-xe4
aero
ui-design
simplecov
user-forums
voice-recording
msinfo32
java.lang.class
wcf-callbacks
background-repeat
filelock
representation
uipasteboard
kernel32
libxslt
turbine
mongrel
raw-data
bucket
wmd-editor
fxruby
ntruencrypt
index.dat
stretchblt
objectinstantiation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App