Filemaker api retruns 958 error code in php - php

I am trying to access FileMaker by using curl PHP. here I am not using filmmaker PHP class. I am importing the records from the filmmaker into the Prestashop site. when admin delete the product in the Prestashop its also deleted in the FileMaker database
$nome = 'http://ipaddress:port/fmi/xml/FMPXMLRESULT.xml?-db=tablename&-lay=export&recordid=$recordid&-delete';
$cURL = curl_init($nome);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_FAILONERROR, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, $header_fields);
$response = curl_exec($cURL);
if ($cURL_err = curl_errno($cURL)) {
die(__FILE__ . "(" . __LINE__ . "): Communication Error: (' . $cURL_err . ')" .
curl_error($cURL));
}
curl_close($cURL);
//Removed the Headers.
when I am executing the code filmmaker return error code 958.

after some analyze.
if we want edit,delete,update the record in the filemaker.we must use the -recid.
i made mistake on API
$nome = 'http://ipaddress:port/fmi/xml/FMPXMLRESULT.xml?-db=tablename&-lay=export&recordid=$recordid&-delete';
it should be
$nome = 'http://ipaddress:port/fmi/xml/FMPXMLRESULT.xml?-db=database&-lay=export&-recid=$recordid&-delete';
after changed its working correctly.Here I attached some example API for getting records and update the records.
GET all records
http://ip_address:port/fmi/xml/FMPXMLRESULT.xml?-db=database&-lay=layout&-findall
Get range of records
http://ip_address:port/fmi/xml/FMPXMLRESULT.xml?-db=Magazzino&-lay=export&-max=100&-findall
Get specific Record
http://ip_address:port/fmi/xml/FMPXMLRESULT.xml?-db=database&-lay=export&fieldname=field_value&-find
Insert New
http://ip_address:port/fmi/xml/FMPXMLRESULT.xml?-db=database&-lay=export&fieldname=field_value&-new
edit record
http://ip_address:port/fmi/xml/FMPXMLRESULT.xml?-db=database&-lay=export&-recid=record_id&-edit
NOTE: Two way to access filmmaker database 1.using FileMaker class.2.using API

Related

PHP cURL web-scraper intermittently returns error "Recv failure: Connection was reset"

I've programmed a very basic web-scraping tool in PHP using cURL and DOM. I'm running it locally on a Windows 10 box using XAMPP (Apache & MySQL). It scrapes approximately 5 values on 400 pages (~2,000 values in total) on one specific website. The job typically completes in < 120 seconds, but intermittently (about once every 5 runs) it'll stop around the 60 second mark with the following error:
Recv failure: Connection was reset
Probably irrelevant, but all of my scraped data is being thrown into a MySQL table, and a separate .php file is styling the data and presenting it. This part is working fine. The error is being thrown by cURL. Here's my (very trimmed) code:
$html = file_get_html('http://IPAddressOfSiteIAmScraping/subpage/listofitems.html');
//Some code that creates my SQL table.
//Finds all subpages on the site - this part works like a charm.
foreach($html->find('a[href^=/subpage/]') as $uniqueItems){
//3 array variables defined here, which I didn't include in this example.
$path = $uniqueItems->href;
$url = 'http://IPAddressOfSiteIAmScraping' . $path;
//Here's the cURL part - I suspect this is the problem. I am an amateur!
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, trim($url));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); //An attempt to fix it - didn't work.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); //An attempt to fix it - didn't work.
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 1200); //Amount of time I let cURL execute for.
$page = curl_exec($curl);
//This is the part that throws up the connection reset error.
if(curl_errno($curl)) {
echo 'Scraping error: ' . curl_error($curl);
exit; }
curl_close($curl);
//Here we use DOM to begin collecting specific cURLed values we want in our SQL table.
$dom = new DOMDocument;
$dom->encoding = 'utf-8'; //Alows the DOM to display html entities for special characters like รถ.
#$dom->loadHTML(utf8_decode($page)); //Loads the HTML of the cURLed page.
$xpath = new DOMXpath($dom); //Allows us to use Xpath values.
//Xpaths that I've set - this is for the SQL part. Probably irrelevant.
$header = $xpath->query('(//div[#id="wrapper"]//p)[#class="header"][1]');
$price = $xpath->query('//tr[#class="price_tr"]/td[2]');
$currency = $xpath->query('//tr[#class="price_tr"]/td[3]');
$league = $xpath->query('//td[#class="left-column"]/p[1]');
//Here we collect specifically the item name from the DOM.
foreach($header as $e) {
$temp = new DOMDocument();
$temp->appendChild($temp->importNode($e,TRUE));
$val = $temp->saveHTML();
$val = strip_tags($val); //Removes the <p> tag from the data that goes into SQL.
$val = mb_convert_encoding($val, 'html-entities', 'utf-8'); //Allows the HTML entity for special characters to be handled.
$val = html_entity_decode($val); //Converts HTML entities for special characters to the actual character value.
$final = mysqli_real_escape_string($conn, trim($val)); //Defense against SQL injection attacks by canceling out single apostrophes in item names.
$item['title'] = $final; //Here's the item name, ready for the SQL table.
}
//Here's a bunch of code where I write to my SQL table. Again, this part works great!
}
I am not opposed to switching to regex if I need to ditch DOM, but I did three days worth of lurking before I chose DOM over regex. I have spent a lot of time researching this problem, but everything I'm seeing says "Recv failure: Connection was reset by peer", which is not what I am getting. I'm really frustrated that I have to ask for help - I've been doing so great so far - just learning as I go. This is the first thing I've ever written in PHP.
TL;DR: I wrote a cURL web-scraper that works brilliantly only 80% of the time. 20% of the time, for an unknown reason, it errors out with "Recv failure: Connection was reset".
Hopefully someone can help me!! :) Thanks for reading even if you can't!
P.S. if you'd like to see my FULL code, it's at: http://pastebin.com/vf4s0d5L.
After researching this at length (I'd already been researching it for days before posting my question), I've caved in and accepted that this error is probably tied to the site I'm trying to scrape and therefore out of my control.
I did manage to work around it though, so I'll drop my workaround here...
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, trim($url));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 1200); //Amount of time I let cURL execute for.
$page = curl_exec($curl);
if(curl_errno($curl)) {
echo 'Scraping error: ' . curl_error($curl) . '</br>';
echo 'Dropping table...</br>';
$sql = "DROP TABLE table_item_info";
if (!mysqli_query($conn, $sql)) {
echo "Could not drop table: " . mysqli_error($conn);
}
mysqli_close($conn);
echo "TABLE has been dropped. Restarting.</br>";
goto start;
exit; }
curl_close($curl);
Basically, what I've done is implemented error-checking. If the error comes up under curl_errno($curl), I assume it's the connection reset error. That being the case, I drop my SQL table and then jump back to the start of my script using "goto start". Then, at the top of my file I have "start:"
This fixed my problem! Now I don't need to worry about whether the connection was reset or not. My code is smart enough to determine that on its own and reset the script if that was the case.
Hope this helps!

Bing Image Search API results exipres after some time

I am implementing Bing Image Search API in php. I know that Bing API has been changed and now we have to involve that windows azure marketplace thing in-order to use the Bing Image Search API.
I have done that, which means i have opted for a free Bing Search Api subscription which gives me around 5000 transaction per month. Its going all good but the thing is the result which is being fetched is tend to get expired after say 1 month.
Here is the code i am using :
$key = "cricket";
// Replace this value with your account key
$accountKey = 'WEGUEed3yF9CI6ZzVblKD0HoMRG3/rOELkCda9VYsuk=';
$ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';
$WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';
$request = $WebSearchURL . urlencode( '\'' . $key . '\'');
$process = curl_init($request);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD, $accountKey . ":" . $accountKey);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$jsonobj = json_decode($response);
echo('<ul ID="resultList">');
foreach($jsonobj->d->results as $value)
{
echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');
echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>');
}
echo("</ul>");
On running this program i am getting the results, I am getting the image source. But the thing is the image source doesn't seems to be a real image source i mean the URL is something like this :
http://ts4.mm.bing.net/th?id=HN.608026386931518543&pid=15.1
Also this link is expires after a month or so .... Initally i was able to see the image when clicking on the link but it expired after a month and now i can only see a greyish camera with a cross on it which means that the image source has been expired i guess.
If you can let me how can i restrict this thing and also is anything needs to done on the windows azure market place end to get things working for me .
Any help will be appreciated
Thanks
Fix for original images.
On the line 22, where are interpreted received and parsed JSON data
echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');
there is a mistake from Bing.
You can just replace
$value->MediaURL for $value->MediaUrl
and you can get acquire access to original image.

Docusign REST call from CodeIgniter

I'm trying to call the DocuSign REST login information within a CodeIgniter application. The Docusign sample code shows:
// Input your info here:
$integratorKey = '...';
$email = '...#....com';
$password = '...';
$name = 'John Doe';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (to retrieve baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://demo.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
I keep getting a status response of 0. When I echo out the curl all the xml tags have been converted to lowercase (which won't work with Docusign). Has anyone done this call within CodeIgniter? How did you accomplish it? I know my credentials are good because I can do a command line curl and get a response.
I'm not sure what CodeIgniter is doing and why the tags would be converted to lower case but you're right in that DocuSign expects xml tags to begin with a capital letter so that might not work. What you can do, though, is use JSON headers and request bodies instead.
For instance, instead of an XML formatted authentication header like
<DocuSignCredentials>
<Username>username</Username>
<Password>password</Password>
<IntegratorKey>integrator_key</IntegratorKey>
</DocuSignCredentials>
You could use the corresponding JSON auth header like
{
"Username": "username",
"Password": "password",
"IntegratorKey": "integrator_key"
}
The "nodes" still start with a capital but since it's not xml I'm wondering if CodeIgniter maybe leaves it alone. Examples of this can be found at the DocuSign Developer Center on this page.

Google maps response's language issue

I'll try to be short: if you need more info, I'll tell you.
I'm using this code to get infos from Google Maps:
<?php
function getData($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); //Change this to a 1 to return headers
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'http://maps.google.com/maps/geo?output=xml&q=' . urlencode($startPlace);
$url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&gl=IT&address=' . urlencode($startPlace);
$xml = simplexml_load_string($this->getData($this->url)) or die("Error loading xml data");
$points = $xml->Response->Placemark->Point->coordinates;
$provincia = $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->SubAdministrativeAreaName;
$regione =$xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName;
echo $regione."<br>";
preg_match_all("/-*[0-9.]*(?=,)/", $points[0], $matches);
$longitude = $matches[0][0];
$latitude = $matches[0][2];
The code is used to retrieve infos about italian locations and till three days ago, all worked fine, but this morning I saw something strange: $regione returned by code ($xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName;) had an english name.
Let's say the location found be a little town in Lombardia (where 'Lombardia' is the name of the Administrative Area), the Administartive Area name returned by Google Maps was no more 'Lombardia' but 'Lombardy'.
Since this data is used to search in a local database other places in the Administrative area and since the name used in the database is obviously italian name, application doesnìt work anymore.
I'll be grateful for any advice
The problem is solved using a different url, specifying language parameter:
'http://maps.google.com/maps/api/geocode/xml?sensor=false&language=IT&address=' . urlencode($startPlace);
This url type return correct results but defferently formed so it is necessary change the code to access the infos and put them into variables, but this solved my problem

Need help: Reading my Google spreadsheet, keeping it private

Getting super frustrated trying to get this working. Basically this is for a site (x10hosting.com) where I can't include the zend gdata framework, so I'm trying to use the Google Data API with php cURL to access it. The most I've been able to do is return a list of the supplied usernames worksheets, using this script:
<?php
// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "", //username
"Passwd" => '', //password
"service" => "writely",
"source" => "your application name"
);
// Initialize the curl object
$curl = curl_init($clientlogin_url);
// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute
$response = curl_exec($curl);
// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];
echo "The auth string is: ".$auth;
// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
"Authorization: GoogleLogin auth=".$auth,
"GData-Version: 3.0",
);
// Make the request
$key = ;
curl_setopt($curl, CURLOPT_URL, "https://spreadsheets1.google.com/ccc?key=$key");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
// Parse the response
$response = simplexml_load_string($response);
// Output data
foreach($response->entry as $file)
{
echo "File: " . $file->title . "<br />";
echo "Type: " . $file->content["type"] . "<br />";
echo "Author: " . $file->author->name . "<br /><br />";
}
?>
But I can't figure out a way to use this to access one specific worksheet. Please help, this is driving me nuts.
EDIT: Following DASPRiD's advice gives me this error->
Notice:
Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be
removed with 2.0.0; use
Zend_Loader_Autoloader instead in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 266
Warning:
require_once(Zend/Loader/Autoloader.php)
[function.require-once]: failed to
open stream: No such file or directory
in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 267
Fatal error: require_once()
[function.require]: Failed opening
required 'Zend/Loader/Autoloader.php'
(include_path='/home/c3webdev/public_html/library:.:/usr/lib/php:/usr/local/lib/php')
in
/home/c3webdev/public_html/library/Zend/Loader.php
on line 267
A query to the following URL should list you all worksheets of a specific spreadsheet:
http://spreadsheets.google.com/feeds/worksheets/**spreadsheetKey**/private/full
To install and use Zend_Gdata, do the following:
Download the last package (http://framework.zend.com/releases/ZendGdata-1.10.7/ZendGdata-1.10.7.tar.gz) from the Zend Framework website. Now let's assume the following directors structure:
/index.php (your main file)
/library/Zend (extract the library/Zend folder in here)
Now in your index.php, do the following:
set_include_path(
dirname(__FILE__) . '/library'
. PATH_SEPARATOR . get_include_path()
);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
Now you can simply follow the manual (http://framework.zend.com/manual/en/zend.gdata.spreadsheets.html). Interesting for you may be the topics "Get a List of Spreadsheets" for creating the service instance and "Get a List of Worksheets" to fetch all worksheets of a specific spreadsheet.
Update:
It looks like the Zend_Gdata package is not properly packaged. I will note that to get the package fixed. In the meantime, I suggest you to download the complete Zend Framework package. To use the autoloader in 1.8 correctly, do the following instead:
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
Once you get the list of supplied worksheets for that user you can parse through to get the data (thats what you want right? the worksheet data?)
As mentioned above this is how you get the spreadsheets available
http://spreadsheets.google.com/feeds/worksheets/<spreadsheet-key>/private/full
Then from there you can get the url to a specific spreadsheet and then from there you can get the data from that
List returns the data with appropriate headings
https://spreadsheets.google.com/feeds/list/<spreadsheet-key>/<worksheet-id>/private/basic
Cells returns it with defined cells (A1, C23 etc.)
https://spreadsheets.google.com/feeds/cells/0<spreadsheet-key>/<worksheet-id>/private/basic
Here is more info on the google spreadsheets api reference
For a really easy alternative solution without Zend and without Google API this may also help.
You can publish your Google Spreadsheet as csv on the web (with a private URL) and simply access it by fopen/fgetcsv:
https://stackoverflow.com/a/18106727/1300348
Please be aware there is no authentication... so whoever has your url has your data, hence this might not be the right solution for files where there are passwords included.
But maybe it helps someone with a similar problem.

Categories