Jump to content

php script to transfer file


fionatighe

Recommended Posts

Hi everyone,

 

I'm new to the web game so have loads to learn about lots of things.. so if the questions i ask are stupid.. then i apologise in advance..

 

I'm looking into building a magento ecommerce site for a customer who has a specific requirement that I be able to extract all customer/order data daily and give it to her CRM. Her words were can i get the databases to talk to each other.

 

Now i know very little about they're CRM but have arranged to talk to someone over there. Anyhow, i feel the best solution is to set up a cron job to run once a day to firstly create a file, that will have all the details on sales/orders and then secondly, will transmit the file to the server hosting their CRM. (The site and the CRM are not on the same server)

 

How does this sound to people? Is it doable?

 

Regards,

Fiona

Link to comment
https://forums.phpfreaks.com/topic/166782-php-script-to-transfer-file/
Share on other sites

Hi Fiona,

A cron job would be a good way of doing things, however you need to produce a file or string that can be sent to the CRM server that the CRM system can read.

 

It might be worth checking out the CRM system (if it is a white label product) to see if it has some form of API whereby you can use the cron job to run perhaps a CURL request posting an XML report of that days transactions to the CRM.

 

Another (and by no means perfect) solution would be to (assuming that the CRM has an API) write a CURL request (or even AJAX and JSON) that, every time a transaction is made, it posts the transaction information to the CRM server, although this will most likely be quite slow and will slow down your users experience.

 

Finally, if the CRM solution your client has is hosted on a server you have access to and you are comfortable with it, you could always write some code to accept requests from an external source and process them and then write something into your application that utilises this facility on the CRM system.

 

I hope this has helped :-)

 

Thanks

Pete

checking out the CRM system (if it is a white label product) to see if it has some form of API whereby you can use the cron job to run perhaps a CURL request posting an XML report of that days transactions to the CRM.

 

Hi Pete,

 

Firstly thank you for taking the time to respond to my query. I should have mentioned in my original post, that the file with the list of customer/order details would be an XML file.

I do have a question on the above.. what exactly is a CURL request? have you any examples? Do I need anything on my server to enable a CURL request? If so, how much does it cost?

 

Again, many thanks for your help with this,

Regards,

Fiona

Hi Fiona,

No worries.

 

CURL is a free PHP library that is usually installed in most configurations of PHP.

 

Basically, a CURL request is where PHP sends a request (and parameters) to a script on an external site, without the user leaving your site. The receiving script will then take the parameters you have passed to it and return a value, object, array, xml string whatever.

 

The best analogy I can think of is say when you use an online store. You have browsed the store and added some items to your basket. You then go to the checkout page and choose to pay with your credit or debit card. You enter your credit and debit card details and the the money is deducted from your account. However, your average e-commerce site doesn't have the facility to manually pull money out of your account, that is what a payment provider is for such as Protx/SagePay. When you have entered your credit card details, the code on the shop you are purchasing takes the data you gave it and (usually) performs a curl request. It sends that data to a script hosted on the Protx/SagePay server. The service on that server then attempts to withdraw the funds and returns data stating whether the transaction was honored or not. But you don't know it does that because the browser doesn't leave the shop.

 

So yeah, basically, it's a way of posting information to a script on another site to receive a response without the user knowingly leaving the site they where originally on.

 

A code example would be something like:

 

<?php
$request = 'your XML here';
$ch = curl_init('https://crm-server.com/processing-script.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
?>

 

For more information take a look at: http://uk3.php.net/curl

 

Cheers

Pete

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.