Getting STDOUT in iOS from PHP script

时间:2016-05-02 21:40:03

标签: php ios swift

I have a PHP script that executes a local command and prints and flushes the stdout. For example, it would print something like

1 

and then after a second

1 2

and then after a second

1 2 3

So on and so forth. I want to be able to get that data as it comes in iOS. I found this function but it does not return anything until the page fully loads:

@IBAction func doButton (sender:AnyObject!) {
    let url = NSURL(string: "http://mywebsite.local/script.php")!

    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithURL(url, completionHandler: {
        (data, response, error) in
        print(NSString(data: data!, encoding: NSUTF8StringEncoding))
    })

    task.resume()
}

Any ideas on how I can flush the data as it comes?

0 个答案:

没有答案