CURL.PerformInBackground
------------------------

Perform a file transfer in background.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [CURL](component_CURL.md) | [2.5](newinversion25.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CURL.PerformInBackground"; curl ) 

**MBS**( **"CURL.PerformInBackground";** /\* Perform a file transfer in background. \*/  
**$curl**) /\* The CURL session handle. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| curl | The CURL session handle. | $curl |

### Result

Error code. 0 means everything was ok, non-zero means an error occurred.

### Description

Perform a file transfer in background.  
This function is called after the init and all the options are set, and will perform the transfer as described in the options. It must be called with the same handle as input as the [CURL.New](CURLNew.md) call returned.  
  
You can do any amount of calls to PerformInBackground while using the same handle. If you intend to transfer more than one file, you are even encouraged to do so. CURL will then attempt to re-use the same connection for the following transfers, thus making the operations faster, less CPU intense and using less network resources. Just note that you will have to use the option functions between the invokes to set options for the following [CURL.Perform](CURLPerform.md).  
  
You must never call this function simultaneously from two places using the same handle. Let the transfer finish first before invoking it another time. If you want parallel transfers, you must use several curl handles.  
  
Internal buffer for output, debug and header data is cleared before the perform.  
  
While transfer is running, your FileMaker application is not blocked. Be aware that transfer runs in background and you should query status with functions like [CURL.IsRunning](CURLIsRunning.md), [CURL.GetProgressTotalDownload](CURLGetProgressTotalDownload.md), [CURL.GetProgressTotalUpload](CURLGetProgressTotalUpload.md), [CURL.GetProgressCurrentDownload](CURLGetProgressCurrentDownload.md) and [CURL.GetProgressCurrentUpload](CURLGetProgressCurrentUpload.md).  
  
The CURL.PerformInBackground allows you to run a transfer in the background on another thread. FileMaker can do whatever it likes (except quitting) and the transfer continues in the background. Your script can start a download and then use FileMaker script steps to do longer operations like an export of records. When finished, you can pick up the result or get a script triggered.  
If you have a lot of parallel background transfers, better use [CURL.PerformAsync](CURLPerformAsync.md) as it is more efficient, but transfers can timeout if FileMaker is busy.  
### Examples

Run a query in background:

 Set Variable \[ $json ; Value: Get(ScriptParameter) \]   
Set Variable \[ $URL ; Value: "https://yourdomain.com/yourscript.php" \]   
\#   
Set Variable \[ $curl ; Value: MBS ("[CURL.New](CURLNew.md)") \]   
\# configure transfer   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; $URL ) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionPostFields](CURLSetOptionPostFields.md)"; $curl ; $json ) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)"; $curl ; "Content-Type: application/json") \]   
\#   
\# Let the evaluate then free the transfer   
\# Set Variable \[ $r ; Value: MBS ("[CURL.SetFinishedEvaluate](CURLSetFinishedEvaluate.md)"; $curl ; "MBS (\\"[CURL.Release](CURLRelease.md)\\"; $$ID $$)" ) \]   
\# or run a script to handle result   
Set Variable \[ $r ; Value: MBS ("[CURL.SetFinishedScript](CURLSetFinishedScript.md)"; $curl ; Get(FileName); "Transfer Finished" ) \]   
\#   
\# run in background thread asynchronously   
Set Variable \[ $r ; Value: MBS ("CURL.PerformInBackground"; $curl ) \]  
SendLog(JSON) custom function to send message to log server:

 Let(\[  
 curl = MBS ("[CURL.New](CURLNew.md)");  
 r = MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; curl; "https://www.your-domain.com/filemaker/log.php");  
 r = MBS ("[CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)"; curl; "Content-Type: application/json");  
 r = MBS ("[CURL.SetOptionPostFields](CURLSetOptionPostFields.md)"; curl; json);  
 // in case of success, just release it.  
 r = MBS ("[CURL.SetSucceededEvaluate](CURLSetSucceededEvaluate.md)"; curl; "MBS (\\"[CURL.Release](CURLRelease.md)\\"; $$ID $$)" );  
 // in case of failure, trigger script to log error  
 r = MBS ("[CURL.SetFailedScript](CURLSetFailedScript.md)"; curl; Get(FileName); "Transfer Failed" );  
 // start sending in background  
 sent = MBS ("CURL.PerformInBackground"; curl)  
\]; sent)  
### See also

- [CURL.New](CURLNew.md)
- [CURL.SetFailedEvaluate](CURLSetFailedEvaluate.md)
- [CURL.SetFinishedEvaluate](CURLSetFinishedEvaluate.md)
- [CURL.SetFinishedScript](CURLSetFinishedScript.md)
- [CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)
- [CURL.SetOptionPost](CURLSetOptionPost.md)
- [CURL.SetOptionURL](CURLSetOptionURL.md)
- [CURL.SetSucceededEvaluate](CURLSetSucceededEvaluate.md)
- [CURL.SetSucceededScript](CURLSetSucceededScript.md)
- [CURL.SetUpdateProgressDialog](CURLSetUpdateProgressDialog.md)

### Release notes

- **Version 11.4**
    - Added thread pool for Windows for multithreaded functions like [CURL.PerformInBackground](https://www.mbsplugins.eu/CURLPerformInBackground.shtml).

### Example Databases

- [ChatGPT](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/ChatGPT.shtml#1ScriptAnchor_)
- [CURL/Batch Download](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Batch%20Download.shtml#7ScriptAnchor_)
- [CURL/CURL and OnWindowTransaction](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20and%20OnWindowTransaction.shtml#1ScriptAnchor_)
- [CURL/CURL Download in Background](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20in%20Background.shtml#1ScriptAnchor_)
- [CURL/Email/Batch Emailer](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Email/Batch%20Emailer.shtml#7ScriptAnchor_)

### Blog Entries

- [Using ChatGPT in FileMaker](https://www.mbsplugins.de/archive/2024-10-16/Using_ChatGPT_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [Background Log Custom function](https://www.mbsplugins.de/archive/2024-01-09/Background_Log_Custom_function/monkeybreadsoftware_blog_filemaker)
- [Parallel network transfers with MBS Plugin](https://www.mbsplugins.de/archive/2023-12-18/Parallel_network_transfers_wit/monkeybreadsoftware_blog_filemaker)
- [Send Audit Log via CURL in background](https://www.mbsplugins.de/archive/2023-11-30/Send_Audit_Log_via_CURL_in_bac/monkeybreadsoftware_blog_filemaker)
- [How long do you wait for Insert From URL to finish?](https://www.mbsplugins.de/archive/2023-10-10/How_long_do_you_wait_for_Inser/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 11.4](https://www.mbsplugins.de/archive/2021-09-15/New_in_MBS_FileMaker_Plugin_11/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 11.4 - More than 6500 Functions In One Plugin](https://www.mbsplugins.de/archive/2021-09-07/MBS_FileMaker_Plugin_114_-_Mor/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.4pr4](https://www.mbsplugins.de/archive/2021-08-30/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Batch sending Emails in FileMaker via MBS Plugin](https://www.mbsplugins.de/archive/2017-01-10/Batch_sending_Emails_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [CURL Tutorial for Filemaker with MBS Plugin](https://www.mbsplugins.de/archive/2012-11-18/CURL_Tutorial_for_Filemaker_wi/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2024, Seite 17](https://filemaker-magazin.de/neuigkeit/4257-Appetithappen-FMM_202402)

This function checks for a license.

Created 18th August 2014 , last changed 27th December 2023

  
[CURL.PerformAsync](CURLPerformAsync.md) - [CURL.ProcessRelativeURL](CURLProcessRelativeURL.md)

[HTML Version](CURLPerformInBackground.shtml)