VirtualJudge system development 2: submission module this time we will talk about the submission module.
Before writing this article, I saw someone discussing the legitimacy and morality of vj. However, I will not talk about this in this article. we only care about technology.
We use php to implement the commit, so we have to use a kind of thing: curl. However, by default, php does not enable curl support. no matter how you use it, it is enough to make it work. if you don't talk about it, paste the code directly:
Public function POJ_DataPoster_Worker ($ user = "skvj01", $ pass =
"Forskvj", $ id = "1000", $ lang = "0", $ code = "", $ rid = ""){
If (DEBUG)
Echo "[D] => $ user, $ pass, $ id, $ lang, $ rid \ n"; // MySQL $ this-> db = new dMySQL (); // Infomation $ cookie_file =
Tempnam ("./cookie", "cookie"); $ login_url = "http://poj.org/login ";
$ Post_fields = "user_id1 =". $ user. "& password1 =". $ pass. "& url = /";
$ This-> rid = $ rid; $ this-> pid = $ id; $ this-> lang = $ lang;
$ This-> user = $ user; $ this-> pass = $ pass;
// Login $ curl = curl_init ($ login_url );
Curl_setopt ($ curl, CURLOPT_HEADER, 0); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ curl, CURLOPT_COOKIEJAR,
$ Cookie_file); curl_setopt ($ curl, CURLOPT_POST, 1 );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ post_fields );
$ This-> data = curl_exec ($ curl); curl_close ($ curl );
// Submit $ hint_code =/"//". $ rid. "\ n"./$ code; $ post_fields =
'Problem _ id = '. $ id.' & language ='
. $ Lang. '& encoded = 1 & source ='. urlencode ($ hint_code );
// Print_r (base64_encode ($ code); $ curl =
Curl_init ("http://poj.org/submit ");
Curl_setopt ($ curl, CURLOPT_HEADER, 0); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ curl, CURLOPT_COOKIEFILE,
$ Cookie_file); curl_setopt ($ curl, CURLOPT_POST, 1 );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ post_fields );
$ This-> data = curl_exec ($ curl); curl_close ($ curl );
@ Unlink ($ cookie_file );
// Record Information $ this-> info = array (
'Id' => $ rid,
'User' => $ user
);
}
Here we use POJ as an example. records will be generated immediately after POJ is submitted, while HDOJ is not. here we use curl to simulate the submission.
$ Pdw = new POJ_DataPoster_Worker ($ oo_u, $ oo_p, $ list [$ I] ['tid'],
$ List [$ I] ['Lang '], $ list [$ I] ['code'], $ list [$ I] ['id']); $ rrid =
$ Pdw-> getRunID ()
Here, the instance is created and the code is submitted, and the RunID is obtained, which is the remote record ID. As mentioned above, a record will be generated after submission, which is better and can be captured directly. Of course, if it cannot be captured, it is a submission error. Of course, capture is an endless loop, constantly querying the status, and then updating the local records.
As mentioned above, there is a question about how to determine which record is your current record. this solution is as follows:
1. an account is a separate queue, and one is submitted each time;
2. each query only queries the records submitted by this account, not all;
3. add a comment to the code, which contains an absolute ID to capture and match all source codes.
Here 3 is theoretically redundant for the first two, as long as you grasp the first one. However, because every time a page is crawled, this mechanism is added by the way, and insurance is the most important.
Release date: May 4th, 2016 at pm
Last edit time: May 4th, 2016 at pm
This article was created by SpringHack and licensed using the knowledge sharing signature 4.0 International License Agreement
You can repost and reference the document freely, but you must sign the author and indicate the source of the article.