103, 'message' => 'Please provide pid for which status is to be checked.' ); echo json_encode($response); die; } $qry = "SELECT * FROM sa_projects WHERE p_id = {$_GET['pid']}"; $chk = mysqli_query($dist_db,$qry); $p_data = mysqli_fetch_assoc($chk); if ( ($p_data['runnow'] == 2) && !($p_data['cstatus']) ) { $response = array( 'status' => 201, 'message' => 'Process for this pid is completed please fetch the data from other API.' ); } else{ $response = array( 'status' => 104, 'message' => 'Process for this pid is not completed please try after some time.' ); } echo json_encode($response); die; } else{ header("Content-Type: application/json"); // Header to tell response type // Domain Name is must to start the process if if (!empty($_GET['domain'])) { $domain = $_GET['domain']; $p_id = md5("custom_".$domain); $user_id = 0; $pages_to_crawl = $_GET['num_pages']; $qry = "SELECT COUNT(*) FROM sa_projects WHERE p_hash = '{$p_id}'"; $chk = mysqli_query($dist_db,$qry); if (mysqli_num_rows($chk)){ $response = array( 'status' => 100, 'message' => 'Project already inserted using this API, please check the project crawl status through other API call and do accordingly.' ); echo json_encode($response); die; } $qry = "INSERT INTO sa_projects(p_hash,user_id,domain,pages_to_crawl,runnow,expired,cstatus,duplicated,history_created,crawl_no) VALUES('".$p_id."',$user_id,'".$domain."',$pages_to_crawl,0,0,'0',0,0,0)"; mysqli_query($dist_db, $qry); $my_errr = $dist_db->error; if ($dist_db->errno) { $response = array( 'status' => 101, 'message' => 'Mysql error occured...', 'error' => $dist_db->error ); } else { $response = array( 'status' => 200, 'message' => 'Success...', 'pid' => $dist_db->insert_id ); } } else { $response = array( 'status' => 102, 'message' => 'Please provide domain name...' ); } echo json_encode($response); } ?>